@@ -105,28 +105,36 @@ def _airflow_providers() -> List[ConfigProvider]:
105105    task context will not be available. Still we want the provider to function so 
106106    we just test if Airflow can be imported. 
107107    """ 
108-      if   not   is_airflow_installed (): 
109-          return  []
108+ 
109+     providers :  List [ ConfigProvider ]  =  []
110110
111111    try :
112112        # hide stdio. airflow typically dumps tons of warnings and deprecations to stdout and stderr 
113113        with  contextlib .redirect_stdout (io .StringIO ()), contextlib .redirect_stderr (io .StringIO ()):
114-             from  airflow .operators .python  import  get_current_context   # noqa 
115- 
114+             # try to get dlt secrets variable. many broken Airflow installations break here. in that case do not create 
116115            from  airflow .models  import  Variable  # noqa 
117116            from  dlt .common .configuration .providers .airflow  import  AirflowSecretsTomlProvider 
118117            # probe if Airflow variable containing all secrets is present 
119118            from  dlt .common .configuration .providers .toml  import  SECRETS_TOML_KEY 
120119            secrets_toml_var  =  Variable .get (SECRETS_TOML_KEY , default_var = None )
121120
121+             # providers can be returned - mind that AirflowSecretsTomlProvider() requests the variable above immediately 
122+             providers  =  [AirflowSecretsTomlProvider ()]
123+ 
124+             # check if we are in task context and provide more info 
125+             from  airflow .operators .python  import  get_current_context   # noqa 
126+             ti  =  get_current_context ()["ti" ]
127+ 
128+         # log outside of stderr/out redirect 
122129        if  secrets_toml_var  is  None :
123130            message  =  f"Airflow variable '{ SECRETS_TOML_KEY }   +  \
124131                "This Airflow variable is a recommended place to hold the content of secrets.toml."  +  \
125132                "If you do not use Airflow variables to hold dlt configuration or use variables with other names you can ignore this warning." 
126-             ti  =  get_current_context ()["ti" ]
127133            ti .log .warning (message )
134+ 
128135    except  Exception :
129136        # do not probe variables when not in task context 
130137        pass 
131138
132-     return  [AirflowSecretsTomlProvider ()]
139+     # airflow not detected 
140+     return  providers 
0 commit comments