Repository navigation
prevent errors when closing SQLite memory URLs in SqlCatalog - #4464
ialarmedalien wants to merge 1 commit into
Conversation
a67ae9f to
114aa29
Compare
| executor.submit(catalog.list_namespaces).result() | ||
|
|
||
| # closing the main thread connection also closes the worker thread's connection | ||
| with warnings.catch_warnings(record=True) as caught_warnings: |
There was a problem hiding this comment.
Note: these checks, which ensure that cross-thread close() and garbage collection complete successfully, are the same as those performed in the previous test (test_sql_catalog_cross_thread_sqlite_close). Depending on what the policy is on repetition and what a single test should cover, I can delete the previous test / delete the close/garbage collection code in this test / etc.
|
Thanks for digging into this @ialarmedalien! The traceback on close is annoying, but I'm not sure this is the right place to fix it. The branch mostly repeats what SQLAlchemy already does. The pysqlite dialect already does It doesn't fix the underlying problem. With If we want engine = create_engine("sqlite://", poolclass=StaticPool, connect_args={"check_same_thread": False})Access has to be serialized, but the For What do you think? |
Rationale for this change
Currently, if using an
InMemoryCatalog(in-memory sqlite catalog) in a worker thread, closing or garbage collecting in the main thread raises ansqlite3.ProgrammingError. SQLAlchemy'sPool._close_connection()catches the exception, logs anERRORtraceback onsqlalchemy.pool, and leaves the underlyingsqlite3.Connectionopen, which subsequently emitsResourceWarning: unclosed databasewhen garbage collection occurs (Python 3.13+).This PR sets the
check_same_threadconnection argument to default toFalseto allow the connection to be closed and garbage collection to occur.Are these changes tested?
Yes -- see new tests:
check_same_threadparams are respectedAre there any user-facing changes?
No API changes.