amoghrajesh commented on issue #50421:
URL: https://github.com/apache/airflow/issues/50421#issuecomment-2872759764

   @IgV52 let me explain. 
   
   I am trying to narrow down my search radius to fix the issue being faced 
here. Your issue description is not very clear for me to able to reproduce the 
bug you are facing and help in fixing it.
   
   I configured my airflow with this:
   ```
   export AIRFLOW__SECRETS__BACKEND="airflow.secrets.metastore.MetastoreBackend"
   ```
   
   And then tried a simple dag that gets a connection, somewhat like:
   ```
   from __future__ import annotations
   
   from airflow.models.baseoperator import BaseOperator
   from airflow import DAG
   from airflow.sdk import Variable
   from airflow.sdk.definitions.connection import Connection
   
   
   class CustomOperator(BaseOperator):
       def execute(self, context):
           gc = Connection.get("athena_default")
           print("The conn is", gc)
           print("Conn uri is", gc.get_uri())
   
   
   with DAG("example_get_connection_from_defn", schedule=None, catchup=False) 
as dag:
       CustomOperator(task_id="print_conn")
   ```
   
   This till doesn't report the error you are reporting. I get this error:
   ```
   [2025-05-12, 19:45:14] INFO - DAG bundles loaded: dags-folder: 
source="airflow.dag_processing.bundles.manager.DagBundlesManager"
   [2025-05-12, 19:45:14] INFO - Filling up the DagBag from 
/files/dags/dags/get_connection_sdk.py: source="airflow.models.dagbag.DagBag"
   [2025-05-12, 19:45:14] INFO - Secrets backends loaded for worker: count=2: 
backend_classes=["MetastoreBackend","EnvironmentVariablesBackend"]: 
source="supervisor"
   [2025-05-12, 19:45:14] ERROR - Unable to retrieve connection from secrets 
backend (MetastoreBackend). Checking subsequent secrets backend.: source="task"
   RuntimeError: Direct database access via the ORM is not allowed in Airflow 
[3](http://localhost:28080/dags/example_get_connection_from_defn/runs/manual__2025-05-12T14:15:13.756176+00:00/tasks/print_conn?try_number=1#3).0
   File "/opt/airflow/task-sdk/src/airflow/sdk/execution_time/context.py", line 
129 in _get_connection
   
   File "/opt/airflow/airflow-core/src/airflow/utils/session.py", line 100 in 
wrapper
   
   File "/usr/local/lib/python3.9/contextlib.py", line 119 in __enter__
   
   File "/opt/airflow/airflow-core/src/airflow/utils/session.py", line 
[4](http://localhost:28080/dags/example_get_connection_from_defn/runs/manual__2025-05-12T14:15:13.756176+00:00/tasks/print_conn?try_number=1#4)1
 in create_session
   
   File "/opt/airflow/task-sdk/src/airflow/sdk/execution_time/supervisor.py", 
line 253 in __init__
   
   [2025-05-12, 19:45:14] INFO - The conn is 
Connection(conn_id='athena_default', conn_type='athena', description=None, 
host=None, schema=None, login=None, password=None, port=None, extra=None): 
chan="stdout": source="task"
   
[202[5](http://localhost:28080/dags/example_get_connection_from_defn/runs/manual__2025-05-12T14:15:13.756176+00:00/tasks/print_conn?try_number=1#5)-05-12,
 19:45:14] INFO - Conn uri is athena://: chan="stdout": source="task"
   ```
   
   Errors, but works. Hence I am asking for input here.


-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to