Calling __dict__ on a mapped object ruins the session's inner state
I have a mapped class, named Application. My mapper looks something like this:
mapper(Application,app_tbl, properties={
"operacion":app_tbl.c.op,
"actividad":app_tbl.c.activ,
...
}
nothing fancier, just renaming of the columns.
When I call {{{ __dict__ }}} on an object of this class, subsequent calls to session methods, or setters of my object, yield strange errors having to do with the session's state variable, and saying things like this:
{{{
File "/home/libre/work/modellica/occa/trunk/src/occa/model.py", line 72, in setResultVars
self.__setattr__("moduloEvaluacion",varMap.get("moduloEvaluacion"))
File "/usr/local/lib64/python2.5/site-packages/sqlalchemy/orm/attributes.py", line 151, in __set__
if this is a list-based attribute, a new, blank list will be created.
File "/usr/local/lib64/python2.5/site-packages/sqlalchemy/orm/attributes.py", line 449, in set
def __setslice__(self, i, j, other):
AttributeError: 'str' object has no attribute 'dict'
In this code, the call to {{{ self.setattr }}} is done within a method of Application, so self is an object of my mapped class.
It seems very strange to me that calling {{{ dict }}} should affect sqlalchemy's session behavior. I'm using sqlalchemy 0.5.2.
Comments (4)
-
Account Deleted -
repo owner - changed component to orm
dict is entirely accessible on mapped objects. You will have poor results if you populate it since you're bypassing the attribute tracking logic but it wouldn't produce anything like the above.
Please attach a fully reproducing test case to this ticket to illustrate what specifically causes the issue else we'll have to close this ticket.
-
Account Deleted I'm awfully sorry. I discovered the cause of my problem. I was later on in my code, changing the type of the values in the dictionary. I didn't know changing the dictionary values would change my object's attributes as well, I thought it was a copy. So it has nothing to do with sqlalchemy: obviously changing the type of the attributes, messes up the mapper logic. Please dismiss my ticket, and sorry for wasting your time.
-
repo owner - changed status to invalid
not a problem....
- Log in to comment
Sorry, I screwed up with the format in this post :(