avernusheros / avernus

0 stars 0 forks source link

[SQLalchemy] Object creation in thread #276

Closed wsteitz closed 11 years ago

wsteitz commented 11 years ago

If a threaded task like getting historical quotations is creating objects and wants to add them to their Session, but the object is already present in another Session, we fail:

Traceback (most recent call last): File "/home/bastian/workspace/avernus/avernus/gui/threads.py", line 36, in run for ret in self.generator(self.args): File "/home/bastian/workspace/avernus/avernus/datasource_manager.py", line 105, in get_historical_prices low=qt[5], close=qt[6], vol=qt[7]) File "/home/bastian/workspace/avernus/avernus/controller/asset_controller.py", line 98, in new_quotation Session().add(qu) File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", line 1223, in add self._save_or_update_state(state) File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", line 1232, in _save_or_update_state self._save_or_update_impl(state) File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", line 1462, in _save_or_update_impl self._save_impl(state) File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", line 1435, in _save_impl self._attach(state) File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", line 1492, in _attach state.session_id, self.hash_key)) InvalidRequestError: Object '<Quotation at 0x1c33a50>' is already attached to session '1' (this is '2')


Imported from Launchpad using lp2gh.

wsteitz commented 11 years ago

(by bastian-kennel) don't know if the fix is right, because there is only ever one quotation arriving, but to me this seems like another problem