-
-
Notifications
You must be signed in to change notification settings - Fork 38.2k
Make sqlalchemy engine connect listener recorder specific #34908
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
Changes from all commits
c10a74e
4a90a41
ae9a0d0
897025c
ac7f598
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,9 +9,7 @@ | |
| import time | ||
| from typing import Any, Dict, Optional | ||
|
|
||
| from sqlalchemy import create_engine, exc, select | ||
| from sqlalchemy.engine import Engine | ||
| from sqlalchemy.event import listens_for | ||
| from sqlalchemy import create_engine, event as sqlalchemy_event, exc, select | ||
| from sqlalchemy.orm import scoped_session, sessionmaker | ||
| from sqlalchemy.pool import StaticPool | ||
| import voluptuous as vol | ||
|
|
@@ -488,15 +486,13 @@ def _setup_connection(self): | |
| """Ensure database is ready to fly.""" | ||
| kwargs = {} | ||
|
|
||
| # pylint: disable=unused-variable | ||
| @listens_for(Engine, "connect") | ||
| def setup_connection(dbapi_connection, connection_record): | ||
| def setup_recorder_connection(dbapi_connection, connection_record): | ||
| """Dbapi specific connection settings.""" | ||
|
|
||
| # We do not import sqlite3 here so mysql/other | ||
| # users do not have to pay for it to be loaded in | ||
| # memory | ||
| if self.db_url == "sqlite://" or ":memory:" in self.db_url: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This changes behavior. If you specify just During tests we run with an in-memory DB.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That logic should still be below. This fixes a regression I caused in b09b572 |
||
| if self.db_url.startswith("sqlite://"): | ||
| old_isolation = dbapi_connection.isolation_level | ||
| dbapi_connection.isolation_level = None | ||
| cursor = dbapi_connection.cursor() | ||
|
|
@@ -519,6 +515,9 @@ def setup_connection(dbapi_connection, connection_record): | |
| self.engine.dispose() | ||
|
|
||
| self.engine = create_engine(self.db_url, **kwargs) | ||
|
|
||
| sqlalchemy_event.listen(self.engine, "connect", setup_recorder_connection) | ||
|
|
||
| Base.metadata.create_all(self.engine) | ||
| self.get_session = scoped_session(sessionmaker(bind=self.engine)) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha oops 😆