我遇到了一个非常奇怪的bug,很难重现:AttributeError: 'list' object has no attribute '_sa_adapter'
。它似乎来自于一对多的关系,但一切看起来都很好,我不能简单地复制这个bug。如果我单独运行测试套件,没有bug,只有在整个测试运行时才会发生。可能是因为没有清洗干净。。。在
以下是完整的堆栈:
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'
你知道它从哪里来吗?在
谢谢
Chx公司
我的例子是另一个会话仍在另一个线程(调度程序1)中打开。所以,我让那个线程在作业被激活后关闭会话,http服务器线程工作起来很有魅力。在
这意味着你不恰当地操作了一个插入指令的对象,比如说,
myobject.__dict__[somekey] = [1, 2, 3]
。映射对象不支持直接__dict__
操作。在旧线程,但对于以后查看的任何人,您需要确保您的值正在通过setattr以便SA的映射有机会被拦截。所以你可以:
或者
^{pr2}$相关问题 更多 >
编程相关推荐