charlax charlax - 2 months ago 11
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
self.client.save()
File "/Users/ca/[REDACTED].py", line 370, in save
Session.add(self)
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/scoping.py", 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/session.py", line 1223, in add
self._save_or_update_state(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/session.py", line 1238, in _save_or_update_state
halt_on=self._contains_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/mapper.py", 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/properties.py", 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/attributes.py", 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?

Thanks,

Chx

Answer

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.

Comments