回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我遇到了一个非常奇怪的bug,很难重现:<code>AttributeError: 'list' object has no attribute '_sa_adapter'</code>。它似乎来自于一对多的关系,但一切看起来都很好,我不能简单地复制这个bug。如果我单独运行测试套件,没有bug,只有在整个测试运行时才会发生。可能是因为没有清洗干净。。。在</p>
<p>以下是完整的堆栈:</p>
<pre><code>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'
</code></pre>
<p>你知道它从哪里来吗?在</p>
<p>谢谢</p>
<p>Chx公司</p>