This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new ad3224cc61 Added support for additional sql alchemy session args
(#41048)
ad3224cc61 is described below
commit ad3224cc610604d1d2b6a6577dfe8fe944570acb
Author: Pavan Sharma <[email protected]>
AuthorDate: Mon Aug 5 15:19:57 2024 +0530
Added support for additional sql alchemy session args (#41048)
---
airflow/config_templates/config.yml | 11 +++++++++++
airflow/settings.py | 29 +++++++++++++++++++++--------
docs/spelling_wordlist.txt | 1 +
3 files changed, 33 insertions(+), 8 deletions(-)
diff --git a/airflow/config_templates/config.yml
b/airflow/config_templates/config.yml
index 53ab612266..782c5217c7 100644
--- a/airflow/config_templates/config.yml
+++ b/airflow/config_templates/config.yml
@@ -675,6 +675,17 @@ database:
type: string
example: 'airflow_local_settings.connect_args'
default: ~
+ sql_alchemy_session_maker:
+ description: |
+ Important Warning: Use of sql_alchemy_session_maker Highly Discouraged
+ Import path for function which returns 'sqlalchemy.orm.sessionmaker'.
+ Improper configuration of sql_alchemy_session_maker can lead to
serious issues,
+ including data corruption, unrecoverable application crashes. Please
review the SQLAlchemy
+ documentation for detailed guidance on proper configuration and best
practices.
+ version_added: 2.9.4
+ type: string
+ example: 'airflow_local_settings._sessionmaker'
+ default: ~
load_default_connections:
description: |
Whether to load the default connections that ship with Airflow when
``airflow db init`` is called.
diff --git a/airflow/settings.py b/airflow/settings.py
index 96e852f278..f7ce1e4b11 100644
--- a/airflow/settings.py
+++ b/airflow/settings.py
@@ -62,6 +62,14 @@ except Exception:
log.info("Configured default timezone %s", TIMEZONE)
+if conf.has_option("database", "sql_alchemy_session_maker"):
+ log.info(
+ '[Warning] Found config "sql_alchemy_session_maker", make sure you
know what you are doing.\n'
+ "[Warning] Improper configuration of sql_alchemy_session_maker can
lead to serious issues, "
+ "including data corruption, unrecoverable application crashes.\n"
+ "[Warning] Please review the SQLAlchemy documentation for detailed
guidance on "
+ "proper configuration and best practices."
+ )
HEADER = "\n".join(
[
@@ -457,14 +465,19 @@ def configure_orm(disable_connection_pool=False,
pool_class=None):
setup_event_handlers(engine)
- Session = scoped_session(
- sessionmaker(
- autocommit=False,
- autoflush=False,
- bind=engine,
- expire_on_commit=False,
- )
- )
+ if conf.has_option("database", "sql_alchemy_session_maker"):
+ _session_maker = conf.getimport("database",
"sql_alchemy_session_maker")
+ else:
+
+ def _session_maker(_engine):
+ return sessionmaker(
+ autocommit=False,
+ autoflush=False,
+ bind=_engine,
+ expire_on_commit=False,
+ )
+
+ Session = scoped_session(_session_maker(engine))
def
force_traceback_session_for_untrusted_components(allow_tests_to_use_db=False):
diff --git a/docs/spelling_wordlist.txt b/docs/spelling_wordlist.txt
index b8b3c60a0d..29d5f6d58a 100644
--- a/docs/spelling_wordlist.txt
+++ b/docs/spelling_wordlist.txt
@@ -1451,6 +1451,7 @@ serializer
serializers
serverless
ServiceAccount
+sessionmaker
setattr
setdefault
setMachineType