charlax charlax - 1 year ago 118
Python Question

SQLAlchemy: object has no attribute '_sa_adapter'

I run into a very strange bug, quite hard to reproduce:

AttributeError: 'list' object has no attribute '_sa_adapter'
. It seems it would come from one-to-many relationship, but everything looks fine and I can't get to simply reproduce the bug. If I run the test suite alone, there's no bug, it only happens when the whole test are run. Maybe it comes from something that was not cleaned properly...

Here is the full stack:

Traceback (most recent call last):
File "/Users/ca/[REDACTED].py", line 79, in setUp
File "/Users/ca/[REDACTED].py", line 370, in save
File "/Users/ca/.pythonbrew/venvs/Python-2.7.3/api/lib/python2.7/site-packages/SQLAlchemy-0.7.5-py2.7-macosx-10.7-x86_64.egg/sqlalchemy/orm/", line 113, in do
return getattr(self.registry(), name)(*args, **kwargs)
File "/Users/ca/.pythonbrew/venvs/Python-2.7.3/api/lib/python2.7/site-packages/SQLAlchemy-0.7.5-py2.7-macosx-10.7-x86_64.egg/sqlalchemy/orm/", line 1223, in add
File "/Users/ca/.pythonbrew/venvs/Python-2.7.3/api/lib/python2.7/site-packages/SQLAlchemy-0.7.5-py2.7-macosx-10.7-x86_64.egg/sqlalchemy/orm/", line 1238, in _save_or_update_state
File "/Users/ca/.pythonbrew/venvs/Python-2.7.3/api/lib/python2.7/site-packages/SQLAlchemy-0.7.5-py2.7-macosx-10.7-x86_64.egg/sqlalchemy/orm/", line 1814, in cascade_iterator
parent_dict, visited_states, halt_on))
File "/Users/ca/.pythonbrew/venvs/Python-2.7.3/api/lib/python2.7/site-packages/SQLAlchemy-0.7.5-py2.7-macosx-10.7-x86_64.egg/sqlalchemy/orm/", line 817, in cascade_iterator
get_all_pending(state, dict_)
File "/Users/ca/.pythonbrew/venvs/Python-2.7.3/api/lib/python2.7/site-packages/SQLAlchemy-0.7.5-py2.7-macosx-10.7-x86_64.egg/sqlalchemy/orm/", line 775, in get_all_pending
current = getattr(current, '_sa_adapter')
AttributeError: 'list' object has no attribute '_sa_adapter'

Do you know where it could come from?



Answer Source

It means you are manipulating an instrumented object inappropriately – such as saying, myobject.__dict__[somekey] = [1, 2, 3]. Direct __dict__ manipulation is not supported on mapped objects.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download