diff --git a/providers/openlineage/src/airflow/providers/openlineage/conf.py b/providers/openlineage/src/airflow/providers/openlineage/conf.py index c7300d298e245..21e905bf88be2 100644 --- a/providers/openlineage/src/airflow/providers/openlineage/conf.py +++ b/providers/openlineage/src/airflow/providers/openlineage/conf.py @@ -136,9 +136,17 @@ def is_disabled() -> bool: if _is_true(os.getenv("OPENLINEAGE_DISABLED", "")): # Check legacy variable return True - # Check if both 'transport' and 'config_path' are not present and also - # if legacy 'OPENLINEAGE_URL' environment variables is not set - return transport() == {} and config_path(True) == "" and os.getenv("OPENLINEAGE_URL", "") == "" + if transport(): # Check if transport is present + return False + if config_path(True): # Check if config file is present + return False + if os.getenv("OPENLINEAGE_URL"): # Check if url simple env var is present + return False + # Check if any transport configuration env var is present + if any(k.startswith("OPENLINEAGE__TRANSPORT") and v for k, v in os.environ.items()): + return False + + return True # No transport configuration is present, we can disable OpenLineage @cache diff --git a/providers/openlineage/tests/unit/openlineage/test_conf.py b/providers/openlineage/tests/unit/openlineage/test_conf.py index cdfb27d406bb6..c8b5441fd4d7c 100644 --- a/providers/openlineage/tests/unit/openlineage/test_conf.py +++ b/providers/openlineage/tests/unit/openlineage/test_conf.py @@ -476,6 +476,39 @@ def test_is_disabled_empty_conf_option(): assert is_disabled() is True +@mock.patch.dict(os.environ, {_VAR_URL: "", "OPENLINEAGE__TRANSPORT": '{"type": "console"}'}, clear=True) +@conf_vars( + { + (_CONFIG_SECTION, _CONFIG_OPTION_CONFIG_PATH): "", + (_CONFIG_SECTION, _CONFIG_OPTION_TRANSPORT): "", + } +) +def test_is_disabled_env_variables_present(): + assert is_disabled() is False + + +@mock.patch.dict(os.environ, {_VAR_URL: "", "OPENLINEAGE__TRANSPORT": ""}, clear=True) +@conf_vars( + { + (_CONFIG_SECTION, _CONFIG_OPTION_CONFIG_PATH): "", + (_CONFIG_SECTION, _CONFIG_OPTION_TRANSPORT): "", + } +) +def test_is_disabled_env_variables_not_present(): + assert is_disabled() is True + + +@mock.patch.dict(os.environ, {_VAR_URL: "", "OPENLINEAGE__TRANSPOR": '{"type": "console"}'}, clear=True) +@conf_vars( + { + (_CONFIG_SECTION, _CONFIG_OPTION_CONFIG_PATH): "", + (_CONFIG_SECTION, _CONFIG_OPTION_TRANSPORT): "", + } +) +def test_is_disabled_env_variables_not_present_typo(): + assert is_disabled() is True + + @mock.patch.dict(os.environ, {_VAR_URL: ""}, clear=True) @conf_vars( {