an exception which occurs when forming row processors in loading.py leaves the cursor open

Issue #3285 resolved
Mike Bayer repo owner created an issue

e.g. such as this:

#!

test/orm/test_eager_relations.py::EagerTest::test_disable_dynamic FAILED

===================================================== FAILURES ======================================================
__________________________________________ EagerTest.test_disable_dynamic ___________________________________________
Traceback (most recent call last):
  File "/home/mbayer/dev/sqlalchemy/test/orm/test_eager_relations.py", line 433, in test_disable_dynamic
    sess.query(User).options(joinedload(User.addresses)).first()
  File "/home/mbayer/dev/sqlalchemy/test/../lib/sqlalchemy/orm/query.py", line 2447, in first
    ret = list(self[0:1])
  File "/home/mbayer/dev/sqlalchemy/test/../lib/sqlalchemy/orm/query.py", line 2283, in __getitem__
    return list(res)
  File "/home/mbayer/dev/sqlalchemy/test/../lib/sqlalchemy/orm/loading.py", line 50, in instances
    for query_entity in query._entities
  File "/home/mbayer/dev/sqlalchemy/test/../lib/sqlalchemy/orm/query.py", line 3280, in row_processor
    polymorphic_discriminator=self._polymorphic_discriminator
  File "/home/mbayer/dev/sqlalchemy/test/../lib/sqlalchemy/orm/loading.py", line 249, in instance_processor
    context, path, mapper, result, adapter, populators)
  File "/home/mbayer/dev/sqlalchemy/test/../lib/sqlalchemy/orm/interfaces.py", line 477, in create_row_processor
    mapper, result, adapter, populators)
  File "/home/mbayer/dev/sqlalchemy/test/../lib/sqlalchemy/orm/strategies.py", line 1442, in create_row_processor
    self
InvalidRequestError: 'User.addresses' does not support object population - eager loading cannot be applied.

in that test, if we just swallow the error, the cursor stays open, and pypy gets screwed up; even closing the connection it keeps the table locked.

Comments (2)

  1. Mike Bayer reporter
    • Fixed bug where if an exception were thrown at the start of a :class:.Query before it fetched results, particularly when row processors can't be formed, the cursor would stay open with results pending and not actually be closed. This is typically only an issue on an interpreter like Pypy where the cursor isn't immediately GC'ed, and can in some circumstances lead to transactions/ locks being open longer than is desirable. fixes #3285

    → <<cset 57f684b4b4a6>>

  2. Mike Bayer reporter
    • Fixed bug where if an exception were thrown at the start of a :class:.Query before it fetched results, particularly when row processors can't be formed, the cursor would stay open with results pending and not actually be closed. This is typically only an issue on an interpreter like Pypy where the cursor isn't immediately GC'ed, and can in some circumstances lead to transactions/ locks being open longer than is desirable. fixes #3285

    Conflicts: lib/sqlalchemy/orm/loading.py

    → <<cset 93978ce3ae84>>

  3. Log in to comment