Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOManager tests produce sqlite3.ProgrammingError Cannot operate on a closed database #2984

Open
zaneselvans opened this issue Oct 27, 2023 · 3 comments
Labels
dagster Issues related to our use of the Dagster orchestrator sqlite Issues related to interacting with sqlite databases testing Writing tests, creating test data, automating testing, etc.

Comments

@zaneselvans
Copy link
Member

zaneselvans commented Oct 27, 2023

When running the io_manager unit tests, the following error crops up sporadically, but doesn't cause the tests to fail.

Apparently this has been happening for a while, but because it wasn't actually causing any tests to fail, we didn't notice. Seems odd. There are a lot of Alembic logging messages that crop up in the same area of the tests as well.

Running the following set of unit tests repeatedly should eventually surface the errors:

pytest test/unit/io_managers_test.py

On some platforms it seems to happen much more frequently than others.

2023-10-27 13:45:35 [   ERROR] sqlalchemy.pool.impl.NullPool:791 Exception during reset or similar
Traceback (most recent call last):
  File "/Users/zane/miniforge3/envs/pudl-dev/lib/python3.11/site-packages/dagster/_core/execution/api.py", line 293, in ephemeral_instance_if_missing
    yield ephemeral_instance
  File "/Users/zane/miniforge3/envs/pudl-dev/lib/python3.11/site-packages/dagster/_core/execution/build_resources.py", line 108, in build_resources
    yield instantiated_resources.build(
GeneratorExit

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/zane/miniforge3/envs/pudl-dev/lib/python3.11/site-packages/sqlalchemy/pool/base.py", line 763, in _finalize_fairy
    fairy._reset(pool, transaction_was_reset)
  File "/Users/zane/miniforge3/envs/pudl-dev/lib/python3.11/site-packages/sqlalchemy/pool/base.py", line 1038, in _reset
    pool._dialect.do_rollback(self)
  File "/Users/zane/miniforge3/envs/pudl-dev/lib/python3.11/site-packages/sqlalchemy/engine/default.py", line 683, in do_rollback
    dbapi_connection.rollback()
sqlite3.ProgrammingError: Cannot operate on a closed database.
2023-10-27 13:45:35 [   ERROR] sqlalchemy.pool.impl.NullPool:791 Exception during reset or similar
Traceback (most recent call last):
  File "/Users/zane/miniforge3/envs/pudl-dev/lib/python3.11/site-packages/dagster/_core/execution/api.py", line 293, in ephemeral_instance_if_missing
    yield ephemeral_instance
  File "/Users/zane/miniforge3/envs/pudl-dev/lib/python3.11/site-packages/dagster/_core/execution/build_resources.py", line 108, in build_resources
    yield instantiated_resources.build(
GeneratorExit

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/zane/miniforge3/envs/pudl-dev/lib/python3.11/site-packages/sqlalchemy/pool/base.py", line 763, in _finalize_fairy
    fairy._reset(pool, transaction_was_reset)
  File "/Users/zane/miniforge3/envs/pudl-dev/lib/python3.11/site-packages/sqlalchemy/pool/base.py", line 1038, in _reset
    pool._dialect.do_rollback(self)
  File "/Users/zane/miniforge3/envs/pudl-dev/lib/python3.11/site-packages/sqlalchemy/engine/default.py", line 683, in do_rollback
    dbapi_connection.rollback()
sqlite3.ProgrammingError: Cannot operate on a closed database.
@zaneselvans zaneselvans added testing Writing tests, creating test data, automating testing, etc. sqlite Issues related to interacting with sqlite databases dagster Issues related to our use of the Dagster orchestrator labels Oct 27, 2023
@jdangerx
Copy link
Member

I was frustrated by this recently and did some more digging, here's what I found:

  • this appears to be happening after the pytest run completes, and, correspondingly, after the teardown functions have run
  • it seems like maybe dagster is trying to clean up the database for its ephemeral instance, after pytest has already cleaned up that database? not quite sure how the dagster instance lifecycle works in test.

@jdangerx jdangerx moved this from New to Backlog in Catalyst Megaproject Nov 11, 2023
@LouisAuneau
Copy link

We are facing the same issue. Did you manage to find a workaround or fix ?

@zaneselvans
Copy link
Member Author

We didn't really figure out what was going on here, but I think we tried to be more careful about always using context managers to ensure the DB connections were getting closed in the IO Managers, and we don't have the problem any more!

Actually maybe we can/should close this issue @jdangerx @bendnorman

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dagster Issues related to our use of the Dagster orchestrator sqlite Issues related to interacting with sqlite databases testing Writing tests, creating test data, automating testing, etc.
Projects
Status: Backlog
Development

No branches or pull requests

3 participants