potiuk commented on code in PR #56044:
URL: https://github.com/apache/airflow/pull/56044#discussion_r2446768696
##########
airflow-core/src/airflow/settings.py:
##########
@@ -382,55 +380,65 @@ def configure_orm(disable_connection_pool=False,
pool_class=None):
"Please use absolute path such as `sqlite:////tmp/airflow.db`."
)
- global NonScopedSession
- global Session
- global engine
+ def _configure_session():
+ """(Re)create engine, NonScopedSession, Session using SQLAlchemy."""
+ global NonScopedSession
+ global Session
+ global engine
- if os.environ.get("_AIRFLOW_SKIP_DB_TESTS") == "true":
- # Skip DB initialization in unit tests, if DB tests are skipped
- Session = SkipDBTestsSession
- engine = None
- return
- log.debug("Setting up DB connection pool (PID %s)", os.getpid())
- engine_args = prepare_engine_args(disable_connection_pool, pool_class)
+ from airflow._shared.secrets_masker import mask_secret
- connect_args = _get_connect_args("sync")
- if SQL_ALCHEMY_CONN.startswith("sqlite"):
- # FastAPI runs sync endpoints in a separate thread. SQLite does not
allow
- # to use objects created in another threads by default. Allowing that
in test
- # to so the `test` thread and the tested endpoints can use common
objects.
- connect_args["check_same_thread"] = False
-
- engine = create_engine(
- SQL_ALCHEMY_CONN,
- connect_args=connect_args,
- **engine_args,
- future=True,
- )
- _configure_async_session()
- mask_secret(engine.url.password)
- setup_event_handlers(engine)
+ log.debug("Setting up DB connection pool (PID %s)", os.getpid())
- if conf.has_option("database", "sql_alchemy_session_maker"):
- _session_maker = conf.getimport("database",
"sql_alchemy_session_maker")
- else:
- _session_maker = functools.partial(
- sessionmaker,
- autocommit=False,
- autoflush=False,
- expire_on_commit=False,
+ if os.environ.get("_AIRFLOW_SKIP_DB_TESTS") == "true":
+ # Skip DB initialization in unit tests, if DB tests are skipped
+ Session = SkipDBTestsSession
+ engine = None
+ return
+
+ engine_args = prepare_engine_args(disable_connection_pool, pool_class)
+
+ connect_args = _get_connect_args("sync")
+ if SQL_ALCHEMY_CONN.startswith("sqlite"):
+ connect_args["check_same_thread"] = False
Review Comment:
Would be nice to keep the comment.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]