Python SQLAlchemy挂着一个;萨瓦宁:此收藏已作废;
我已经遇到这个问题好几天了,仍然不知道为什么在运行单元测试时SQLAlchemy总是挂在这个消息上 /usr/local/lib/python3.4/site packages/sqlalchemy/orm/collections.py:722:SAWarning:此集合已无效。 self.\u warn\u invalidated() 当我添加了几行代码来保存一个新的模型实例(比如模型MC的实例)时,就会发生这种情况,该实例引用了另一个新提交的模型实例(比如模型M的实例,M.id=MC.M_id)。不幸的是,大多数代码都是私有的,所以我不能像我希望的那样分享太多的参考代码 当我使用Python SQLAlchemy挂着一个;萨瓦宁:此收藏已作废;,python,sqlalchemy,flask-sqlalchemy,Python,Sqlalchemy,Flask Sqlalchemy,我已经遇到这个问题好几天了,仍然不知道为什么在运行单元测试时SQLAlchemy总是挂在这个消息上 /usr/local/lib/python3.4/site packages/sqlalchemy/orm/collections.py:722:SAWarning:此集合已无效。 self.\u warn\u invalidated() 当我添加了几行代码来保存一个新的模型实例(比如模型MC的实例)时,就会发生这种情况,该实例引用了另一个新提交的模型实例(比如模型M的实例,M.id=MC.M_i
ctrl+c
摆脱挂起状态时,堆栈跟踪如下所示:
Aborted!
results = run_tests(test_names)
File "tests/run.py", line 14, in run_tests
return testRunner.run(tests)
File "/usr/local/lib/python3.4/unittest/runner.py", line 168, in run
test(result)
File "/usr/local/lib/python3.4/unittest/suite.py", line 87, in __call__
return self.run(*args, **kwds)
File "/usr/local/lib/python3.4/unittest/suite.py", line 125, in run
test(result)
File "/usr/local/lib/python3.4/unittest/case.py", line 625, in __call__
return self.run(*args, **kwds)
File "/usr/local/lib/python3.4/unittest/case.py", line 577, in run
testMethod()
File "/api/tests/test_messaging.py", line 292, in test_create_message
self._create_message_credit(self.member)
File "/api/tests/test_messaging.py", line 86, in _create_message_credit
msg_credits += _create_credits(diffs)
File "/usr/local/lib/python3.4/site-packages/sqlalchemy/orm/collections.py", line 1164, in __iadd__
self.append(value)
File "/usr/local/lib/python3.4/site-packages/sqlalchemy/orm/collections.py", line 1057, in append
item = __set(self, item, _sa_initiator)
File "/usr/local/lib/python3.4/site-packages/sqlalchemy/orm/collections.py", line 1029, in __set
item = executor.fire_append_event(item, _sa_initiator)
File "/usr/local/lib/python3.4/site-packages/sqlalchemy/orm/collections.py", line 726, in fire_append_event
item, initiator)
File "/usr/local/lib/python3.4/site-packages/sqlalchemy/orm/attributes.py", line 929, in fire_append_event
value = fn(state, value, initiator or self._append_token)
File "/usr/local/lib/python3.4/site-packages/sqlalchemy/orm/unitofwork.py", line 44, in append
not sess._contains_state(item_state):
File "/usr/local/lib/python3.4/site-packages/sqlalchemy/orm/session.py", line 1961, in _contains_state
return state in self._new or self.identity_map.contains_state(state)
File "/usr/local/lib/python3.4/site-packages/sqlalchemy/orm/identity.py", line 98, in contains_state
return dict.get(self, state.key) is state
KeyboardInterrupt
我正在运行
python3.4.3
、flasksqlalchemy 2.0
和SQLAlchemy 0.9.8
您确定这不是原始项目bug tracker中的bug报告材料吗?@silpol感谢您的建议。它原来是由SQLAlchemy之外的一个bug引起的。然而,我仍然想理解为什么它“挂”在上面。因此,我将花更多的时间创建一个样本测试,我可以复制挂起行为,然后提交。