kennethreitz / records

SQL for Humans™
https://pypi.python.org/pypi/records/
ISC License
7.15k stars 570 forks source link

Example fails with `Cannot operate on a closed database.` #128

Closed jian-en closed 5 months ago

jian-en commented 6 years ago

I see records will be upgraded to v5.3 supporting the connection pool. But it does not support lazy loading that the tests not cover.

However, when running the example it will report: "sqlalchemy.exc.ProgrammingError: (sqlite3.ProgrammingError) Cannot operate on a closed database."

I think it is because the cursor is closed out of the connection and when we want to retrieve the data using the old cursor. it does not exist.

Hope this issue will be fixed before pushed to v5.3.

gdtroszak commented 6 years ago

Excellent catch! And I think your assessment of the problem is spot-on - there is a generator that depends on that cursor being open and it throws the reported error when we attempt to consume off of it. I'll take a closer look and see if I can come up with a solution.

Also, @kennethreitz, the connection pooling change I made (https://github.com/kennethreitz/records/pull/119) does have a non-backwards compatible API change (Database.transaction doesn't behave how it used to). I assume that would warrant a bump to v6.0?

kennethreitz commented 6 years ago

yes

gdtroszak commented 6 years ago

Just to give an update (apologies for the delay). I have a fix for this, but would like to do a bit more testing. Hopefully I'll have a PR ready within a week.

vlcinsky commented 6 years ago

@jian-en PR #147 has refactored test suite and all failing cases are reporting the Cannot operate on a closed database.

vlcinsky commented 6 years ago

Issue #149 shows the same error, but it differs for sqlite:///:memory: (which works well) and for sqlite:///some.file (which fails).

chuangbo commented 3 years ago

For sqlite user, this issue has been fixed in #190 but not yet merged.

Until then, we can install the fix by doing the following

pipenv install git+https://github.com/gdtroszak/records.git@connection-fix-redux#egg=records