5858from airflow .utils .orm_event_handlers import setup_event_handlers
5959from airflow .utils .sqlalchemy import is_sqlalchemy_v1
6060
61- USE_PSYCOPG3 : bool
61+ _USE_PSYCOPG3 : bool
6262try :
6363 from importlib .util import find_spec
6464
6565 is_psycopg3 = find_spec ("psycopg" ) is not None
6666
67- USE_PSYCOPG3 = is_psycopg3 and not is_sqlalchemy_v1 ()
67+ _USE_PSYCOPG3 = is_psycopg3 and not is_sqlalchemy_v1 ()
6868except (ImportError , ModuleNotFoundError ):
69- USE_PSYCOPG3 = False
69+ _USE_PSYCOPG3 = False
7070
7171if TYPE_CHECKING :
7272 from sqlalchemy .engine import Engine
107107 ]
108108)
109109
110- LOGGING_LEVEL = logging .INFO
111-
112- LOG_FORMAT = conf .get ("logging" , "log_format" )
113110SIMPLE_LOG_FORMAT = conf .get ("logging" , "simple_log_format" )
114111
115112SQL_ALCHEMY_CONN : str | None = None
116113SQL_ALCHEMY_CONN_ASYNC : str | None = None
117114PLUGINS_FOLDER : str | None = None
118115DAGS_FOLDER : str = os .path .expanduser (conf .get_mandatory_value ("core" , "DAGS_FOLDER" ))
119116
120- AIO_LIBS_MAPPING = {"sqlite" : "aiosqlite" , "postgresql" : "asyncpg" , "mysql" : "aiomysql" }
121- """
122- Mapping of sync scheme to async scheme.
123-
124- :meta private:
125- """
126-
127117engine : Engine | None = None
128118Session : scoped_session | None = None
129119# NonScopedSession creates global sessions and is not safe to use in multi-threaded environment without
@@ -246,6 +236,9 @@ def load_policy_plugins(pm: pluggy.PluginManager):
246236
247237
248238def _get_async_conn_uri_from_sync (sync_uri ):
239+ AIO_LIBS_MAPPING = {"sqlite" : "aiosqlite" , "postgresql" : "asyncpg" , "mysql" : "aiomysql" }
240+ """Mapping of sync scheme to async scheme."""
241+
249242 scheme , rest = sync_uri .split (":" , maxsplit = 1 )
250243 scheme = scheme .split ("+" , maxsplit = 1 )[0 ]
251244 aiolib = AIO_LIBS_MAPPING .get (scheme )
@@ -327,9 +320,6 @@ def get_bind(
327320 pass
328321
329322
330- AIRFLOW_PATH = os .path .dirname (os .path .dirname (__file__ ))
331-
332-
333323def _is_sqlite_db_path_relative (sqla_conn_str : str ) -> bool :
334324 """Determine whether the database connection URI specifies a relative path."""
335325 # Check for non-empty connection string:
@@ -455,22 +445,21 @@ def clean_in_fork():
455445 register_at_fork (after_in_child = clean_in_fork )
456446
457447
458- DEFAULT_ENGINE_ARGS : dict [str , dict [str , Any ]] = {
459- "postgresql" : (
460- {
461- "executemany_values_page_size" if is_sqlalchemy_v1 () else "insertmanyvalues_page_size" : 10000 ,
462- }
463- | (
464- {}
465- if USE_PSYCOPG3
466- else {"executemany_mode" : "values_plus_batch" , "executemany_batch_page_size" : 2000 }
467- )
468- )
469- }
470-
471-
472448def prepare_engine_args (disable_connection_pool = False , pool_class = None ):
473449 """Prepare SQLAlchemy engine args."""
450+ DEFAULT_ENGINE_ARGS : dict [str , dict [str , Any ]] = {
451+ "postgresql" : (
452+ {
453+ "executemany_values_page_size" if is_sqlalchemy_v1 () else "insertmanyvalues_page_size" : 10000 ,
454+ }
455+ | (
456+ {}
457+ if _USE_PSYCOPG3
458+ else {"executemany_mode" : "values_plus_batch" , "executemany_batch_page_size" : 2000 }
459+ )
460+ )
461+ }
462+
474463 default_args = {}
475464 for dialect , default in DEFAULT_ENGINE_ARGS .items ():
476465 if SQL_ALCHEMY_CONN .startswith (dialect ):
@@ -654,16 +643,39 @@ def prepare_syspath_for_config_and_plugins():
654643
655644def __getattr__ (name : str ):
656645 """Handle deprecated module attributes."""
657- if name == "MASK_SECRETS_IN_LOGS" :
658- import warnings
646+ import warnings
647+
648+ from airflow .exceptions import RemovedInAirflow4Warning
659649
650+ if name == "MASK_SECRETS_IN_LOGS" :
660651 warnings .warn (
661652 "settings.MASK_SECRETS_IN_LOGS has been removed. This shim returns default value of False. "
662653 "Use SecretsMasker.enable_log_masking(), disable_log_masking(), or is_log_masking_enabled() instead." ,
663- DeprecationWarning ,
654+ RemovedInAirflow4Warning ,
664655 stacklevel = 2 ,
665656 )
666657 return False
658+ if name == "WEB_COLORS" :
659+ warnings .warn (
660+ "settings.WEB_COLORS has been removed. This shim returns default value. "
661+ "Please upgrade your provider or integration." ,
662+ RemovedInAirflow4Warning ,
663+ stacklevel = 2 ,
664+ )
665+ return {"LIGHTBLUE" : "#4d9de0" , "LIGHTORANGE" : "#FF9933" }
666+ if name == "EXECUTE_TASKS_NEW_PYTHON_INTERPRETER" :
667+ warnings .warn (
668+ "settings.EXECUTE_TASKS_NEW_PYTHON_INTERPRETER has been removed. This shim returns default value. "
669+ "Please upgrade your provider or integration." ,
670+ RemovedInAirflow4Warning ,
671+ stacklevel = 2 ,
672+ )
673+ return not hasattr (os , "fork" ) or conf .getboolean (
674+ "core" ,
675+ "execute_tasks_new_python_interpreter" ,
676+ fallback = False ,
677+ )
678+
667679 raise AttributeError (f"module '{ __name__ } ' has no attribute '{ name } '" )
668680
669681
@@ -736,26 +748,6 @@ def initialize():
736748 atexit .register (dispose_orm )
737749
738750
739- # Const stuff
740- WEB_COLORS = {"LIGHTBLUE" : "#4d9de0" , "LIGHTORANGE" : "#FF9933" }
741-
742- # Updating serialized DAG can not be faster than a minimum interval to reduce database
743- # write rate.
744- MIN_SERIALIZED_DAG_UPDATE_INTERVAL = conf .getint ("core" , "min_serialized_dag_update_interval" , fallback = 30 )
745-
746- # If set to True, serialized DAGs is compressed before writing to DB,
747- COMPRESS_SERIALIZED_DAGS = conf .getboolean ("core" , "compress_serialized_dags" , fallback = False )
748-
749- CAN_FORK = hasattr (os , "fork" )
750-
751- EXECUTE_TASKS_NEW_PYTHON_INTERPRETER = not CAN_FORK or conf .getboolean (
752- "core" ,
753- "execute_tasks_new_python_interpreter" ,
754- fallback = False ,
755- )
756-
757- USE_JOB_SCHEDULE = conf .getboolean ("scheduler" , "use_job_schedule" , fallback = True )
758-
759751# By default Airflow plugins are lazily-loaded (only loaded when required). Set it to False,
760752# if you want to load plugins whenever 'airflow' is invoked via cli or loaded from module.
761753LAZY_LOAD_PLUGINS : bool = conf .getboolean ("core" , "lazy_load_plugins" , fallback = True )
@@ -765,15 +757,4 @@ def initialize():
765757# loaded from module.
766758LAZY_LOAD_PROVIDERS : bool = conf .getboolean ("core" , "lazy_discover_providers" , fallback = True )
767759
768- # Executors can set this to true to configure logging correctly for
769- # containerized executors.
770- IS_EXECUTOR_CONTAINER = bool (os .environ .get ("AIRFLOW_IS_EXECUTOR_CONTAINER" , "" ))
771- IS_K8S_EXECUTOR_POD = bool (os .environ .get ("AIRFLOW_IS_K8S_EXECUTOR_POD" , "" ))
772- """Will be True if running in kubernetes executor pod."""
773-
774- HIDE_SENSITIVE_VAR_CONN_FIELDS = conf .getboolean ("core" , "hide_sensitive_var_conn_fields" )
775-
776- # Prefix used to identify tables holding data moved during migration.
777- AIRFLOW_MOVED_TABLE_PREFIX = "_airflow_moved"
778-
779760DAEMON_UMASK : str = conf .get ("core" , "daemon_umask" , fallback = "0o077" )
0 commit comments