Strange error with getattr() function

H

Hole

Hi There!

I'm trying to use Zope and the product OpenFlow.

I got the following error while I was using the built-in function
getattr() to retrieve an OpenFlow object:

attribute name must be string


Actually, I surely pass a string as attribute name to getattr()

The code:

#following instruction returns me the string "WorkFlowTest"
openflow_id=container.aq_parent.id

if (hasattr(container,openflow_id):
#the interpreter enter in this block, so
#it's sure that container has an attribute called WorkFlowTest
openflow=getattr(container,openflow_id)

At this point, I got the error: attribute name must be string

The *strange* is that I get the same error even if I pass the attribute
name to the getattr() function as pure string:

getattr(container,"WorkFlowTest")

(sic!!!!!)

I'm a lot confused!
Thanks in advance.
 
H

Hole

Hole ha scritto:
Hi There!

I'm trying to use Zope and the product OpenFlow.

I got the following error while I was using the built-in function
getattr() to retrieve an OpenFlow object:

attribute name must be string


Actually, I surely pass a string as attribute name to getattr()

The code:

#following instruction returns me the string "WorkFlowTest"
openflow_id=container.aq_parent.id

if (hasattr(container,openflow_id):
#the interpreter enter in this block, so
#it's sure that container has an attribute called WorkFlowTest
openflow=getattr(container,openflow_id)

At this point, I got the error: attribute name must be string

I'm wondering if the exception is raised in a hidden function and not
in the explicit call to getattr(). How can I view the traceback in a
script running in zope??
 
G

Gabriel Genellina

I'm trying to use Zope and the product OpenFlow.

Try posting in the Zope list, you surely will have more responses.
I got the following error while I was using the built-in function
getattr() to retrieve an OpenFlow object:

attribute name must be string


Actually, I surely pass a string as attribute name to getattr()

The code:

#following instruction returns me the string "WorkFlowTest"
openflow_id=container.aq_parent.id

Are you sure it's a string? Some objects have an id() method. You
always should use getId().
if (hasattr(container,openflow_id):
#the interpreter enter in this block, so
#it's sure that container has an attribute called WorkFlowTest
openflow=getattr(container,openflow_id)

At this point, I got the error: attribute name must be string

getattr is acquisition-aware so you might be retrieving another thing...
The *strange* is that I get the same error even if I pass the attribute
name to the getattr() function as pure string:

getattr(container,"WorkFlowTest")
(sic!!!!!)

If you're really sure of this, I think the error may occur inside
another function in the getattr chain.



--
Gabriel Genellina
Softlab SRL






__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas
 
G

Gabriel Genellina

I'm wondering if the exception is raised in a hidden function and not
in the explicit call to getattr(). How can I view the traceback in a
script running in zope??

(Which Zope version?)
If you don't catch the exception, an error page will be displayed,
pointing to the error_log object.


--
Gabriel Genellina
Softlab SRL






__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas
 
H

Hole

Gabriel Genellina ha scritto:
(Which Zope version?)
If you don't catch the exception, an error page will be displayed,
pointing to the error_log object.

Hi Gabriel,

thanks a lot for your replies.

I've resolved the problem catching the exception and printing the
traceback in a file.

The problem was, indeed, in a getattr() call performed in another
function, to which I passed an int rather than a string.

Bye!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top