I don't have Oracle, but here's a complete runnable example using MySQL
(hopefully the formatting will survive this time):
import sqlalchemy as sa
import MySQLdb
# start with the wrong password to force a connection error
engine = sa.create_engine("mysql://user:wrong@db/db")
Hello Simon,
I tried your suggestion as POC:
def setup_event_handlers(engine):
@event.listens_for(engine, 'do_connect')
def receive_do_connect(dialect, conn_rec, cargs, cparams):
print("inside do_connect")
print('password %s' % cparams['password'])
try:
print("inside try")
return
I don't know anything about Airflow. Are you sure that each of these
tasks is running inside the same Python interpreter/process? I see
Airflow can distribute tasks among workers:
https://airflow.apache.org/docs/apache-airflow/stable/executor/index.html
This sounds like a problem that is going
As suggested here:
https://docs.sqlalchemy.org/en/14/core/engines.html#fully-replacing-the-dbapi-connect-function
In your do_connect handler, rather than calling engine.connect(), you
need to call cx_Oracle.connect(), and return the result. You can wrap
this in an exception handler that detects
Hello Simon,
Thank you for prompt response. I really appreciate your help. I am trying
to achieve password rotation and we are using secret client to fetch new
password. I tried do_connect event and fetch new password from secret
client, working as expected but we are facing performance issue
I don't really understand what's going on in your code, but you seem
to be calling engine.connect() inside your "do_connect" event handler.
I would expect that to trigger another "do_connect" event, which in
turn will call engine.connect() again, which will trigger another
"do_connect" event, and