SQLAlchemy挂起了" SAWarning:此集合已失效。"

时间:2016-01-15 17:07:44

标签: python sqlalchemy flask-sqlalchemy

我已经遇到了这个问题几天了,但仍然不知道为什么SQLAlchemy在运行单元测试时总会挂起这条消息。

  

/usr/local/lib/python3.4/site-packages/sqlalchemy/orm/collections.py:722:SAWarning:此集合已失效。    self._warn_invalidated()

当我添加几行代码来保存新模型实例(比如模型MC的实例)时会发生这种情况,该实例具有对另一个新提交的模型实例的引用(比如模型M和M.id = MC的实例) 。中)。不幸的是,大多数代码都是私有的,所以我不能按照自己的意愿分享很多参考代码。

当我使用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

我正在Python 3.4.3Flask-SQLAlchemy 2.0SQLAlchemy 0.9.8上运行。

0 个答案:

没有答案