adrian-edbert opened a new issue, #57336:
URL: https://github.com/apache/airflow/issues/57336

   ### Apache Airflow version
   
   3.1.0
   
   ### If "Other Airflow 2/3 version" selected, which one?
   
   _No response_
   
   ### What happened?
   
   Airflow worker failed on getting local filesystem secret backend  
   With an error message: unable to retrieve connection
   
   
   
   ### What you think should happen instead?
   
   Airflow worker should retrieve connection coming from local filesystem 
secrets backend
   
   ### How to reproduce
   
   with dag file
   
   ```
   from __future__ import annotations
   
   from airflow.providers.standard.operators.python import PythonOperator
   
   def print_connection():
       from airflow.sdk.bases.hook import BaseHook
       worker_conn = BaseHook.get_connection("worker_connection_env")
       print(f"worker_connection_env : {worker_conn}")
   
   with DAG(
       dag_id='test_dag',
       catchup=False,
   ):
       test = PythonOperator(task_id='task3', python_callable=print_connection)
       test
   
   ```
   
   on a worker configuration with this env var
   ```
   
AIRFLOW__SECRETS__BACKEND=airflow.secrets.local_filesystem.LocalFilesystemBackend
   AIRFLOW__SECRETS__BACKEND_KWARGS={"connections_file_path": 
"{path_to_config}/connection.yaml"}
   ```
   
   connection.yaml
   
   ```
   worker_connection_env:
     conn_type: Generic
     description: worker specific connection env for sanity test
   ```
   
   this will fail with these message
   ```
   [2025-10-22 11:31:52] ERROR - Unable to retrieve connection from secrets 
backend (LocalFilesystemBackend). Checking subsequent secrets backend. 
source=task loc=context.py:162
   InvalidRequestError: When initializing mapper mapped class 
DagVersion->dag_version, expression 'DagCode' failed to locate a name 
('DagCode'). If this is a class name, consider adding this relationship() to 
the <class 'airflow.models.dag_version.DagVersion'> class after both dependent 
classes have been defined.
   File 
"/home/generic_scheduler/test_airflow/generic_scheduler-venv/lib/python3.12/site-packages/airflow/sdk/execution_time/context.py",
 line 156 in _get_connection
   
   File 
"/home/generic_scheduler/test_airflow/generic_scheduler-venv/lib/python3.12/site-packages/airflow/secrets/local_filesystem.py",
 line 314 in get_connection
   
   File 
"/home/generic_scheduler/test_airflow/generic_scheduler-venv/lib/python3.12/site-packages/airflow/secrets/local_filesystem.py",
 line 311 in _local_connections
   
   File 
"/home/generic_scheduler/test_airflow/generic_scheduler-venv/lib/python3.12/site-packages/airflow/secrets/local_filesystem.py",
 line 273 in load_connections_dict
   
   File 
"/home/generic_scheduler/test_airflow/generic_scheduler-venv/lib/python3.12/site-packages/airflow/secrets/local_filesystem.py",
 line 228 in _create_connection
   
   File "<string>", line 4 in __init__
   
   File 
"/home/generic_scheduler/test_airflow/generic_scheduler-venv/lib/python3.12/site-packages/sqlalchemy/orm/state.py",
 line 476 in _initialize_instance
   
   File 
"/home/generic_scheduler/test_airflow/generic_scheduler-venv/lib/python3.12/site-packages/sqlalchemy/event/attr.py",
 line 346 in __call__
   
   File 
"/home/generic_scheduler/test_airflow/generic_scheduler-venv/lib/python3.12/site-packages/sqlalchemy/orm/mapper.py",
 line 3716 in _event_on_init
   
   File 
"/home/generic_scheduler/test_airflow/generic_scheduler-venv/lib/python3.12/site-packages/sqlalchemy/orm/mapper.py",
 line 1941 in _check_configure
   
   File 
"/home/generic_scheduler/test_airflow/generic_scheduler-venv/lib/python3.12/site-packages/sqlalchemy/orm/mapper.py",
 line 3527 in _configure_registries
   
   File 
"/home/generic_scheduler/test_airflow/generic_scheduler-venv/lib/python3.12/site-packages/sqlalchemy/orm/mapper.py",
 line 3566 in _do_configure_registries
   
   File 
"/home/generic_scheduler/test_airflow/generic_scheduler-venv/lib/python3.12/site-packages/sqlalchemy/orm/mapper.py",
 line 1958 in _post_configure_properties
   
   File 
"/home/generic_scheduler/test_airflow/generic_scheduler-venv/lib/python3.12/site-packages/sqlalchemy/orm/interfaces.py",
 line 231 in init
   
   File 
"/home/generic_scheduler/test_airflow/generic_scheduler-venv/lib/python3.12/site-packages/sqlalchemy/orm/relationships.py",
 line 2150 in do_init
   
   File 
"/home/generic_scheduler/test_airflow/generic_scheduler-venv/lib/python3.12/site-packages/sqlalchemy/orm/relationships.py",
 line 2245 in _process_dependent_arguments
   
   File 
"/home/generic_scheduler/test_airflow/generic_scheduler-venv/lib/python3.12/site-packages/sqlalchemy/util/langhelpers.py",
 line 1113 in __get__
   
   File 
"/home/generic_scheduler/test_airflow/generic_scheduler-venv/lib/python3.12/site-packages/sqlalchemy/orm/relationships.py",
 line 2112 in entity
   
   File 
"/home/generic_scheduler/test_airflow/generic_scheduler-venv/lib/python3.12/site-packages/sqlalchemy/orm/clsregistry.py",
 line 397 in _resolve_name
   
   File 
"/home/generic_scheduler/test_airflow/generic_scheduler-venv/lib/python3.12/site-packages/sqlalchemy/orm/clsregistry.py",
 line 375 in _raise_for_name
   
   File 
"/home/generic_scheduler/test_airflow/generic_scheduler-venv/lib/python3.12/site-packages/sqlalchemy/util/compat.py",
 line 211 in raise_
   
   KeyError: 'DagCode'
   File 
"/home/generic_scheduler/test_airflow/generic_scheduler-venv/lib/python3.12/site-packages/sqlalchemy/orm/clsregistry.py",
 line 393 in _resolve_name
   
   File 
"/home/generic_scheduler/test_airflow/generic_scheduler-venv/lib/python3.12/site-packages/sqlalchemy/util/_collections.py",
 line 746 in __missing__
   
   File 
"/home/generic_scheduler/test_airflow/generic_scheduler-venv/lib/python3.12/site-packages/sqlalchemy/orm/clsregistry.py",
 line 372 in _access_cls
   
   ```
   
   ### Operating System
   
   Ubuntu 20.04.5 LTS (Focal Fossa)
   
   ### Versions of Apache Airflow Providers
   
   _No response_
   
   ### Deployment
   
   Virtualenv installation
   
   ### Deployment details
   
   Virtual env installation using UV
   pip freeze | grep -i airflow
   
   apache-airflow==3.1.0
   apache-airflow-client==3.1.0rc1
   apache-airflow-core==3.1.0.1
   apache-airflow-providers-apache-hdfs==4.10.1
   apache-airflow-providers-apache-spark==5.3.1
   apache-airflow-providers-celery==3.12.1
   apache-airflow-providers-common-compat==1.7.2
   apache-airflow-providers-common-io==1.6.1
   apache-airflow-providers-common-sql==1.27.3
   apache-airflow-providers-fab==2.4.4
   apache-airflow-providers-git==0.0.8
   apache-airflow-providers-http==5.4.0rc1
   apache-airflow-providers-smtp==2.1.1
   apache-airflow-providers-standard==1.4.1
   apache-airflow-task-sdk==1.1.0
   
   
   ### Anything else?
   
   From our test on our fork, changing the import
   `from airflow.models.connection import Connection`
   into 
   `from airflow.sdk.definitions.connection import Connection`
   
   in file `airflow-core/src/airflow/secrets/local_filesystem.py`
   
   works to fix the issue
   
   ### Are you willing to submit PR?
   
   - [x] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


-- 
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]

Reply via email to