GitHub user stemarks added a comment to the discussion: Airflow with virtualenv 
and private repositories

I have attempted to get a version wor work with virtualenv using 
@task.external_python and then creating the venv as part of the dockerfile 
build. but the dockerfile build fails due to conflicts still. I assume it is 
related to using the postgres hook

```
@task.external_python(task_id="mitre_check", 
python="/opt/airflow/mitre-venv/bin/python")
    def callable_mitre_check():
        """Connects to the database and performs a data check."""
        try:
            conn = 
PostgresHook(postgres_conn_id="my_db_id").get_connection("core_id")
            connection_url = URL.create(
                drivername="postgresql+psycopg2",
                username=conn.login,
                password=conn.password,
                host=conn.host,
                port=conn.port,
                database=conn.schema,
            )
            engine = create_engine(connection_url)
            asyncio.run(run_mitre_check(engine))
        except Exception as e:
            logging.error(f"Error in mitre_check: {e}")
            raise  # Reraise the exception to mark the task as failed

    mitre_check = callable_mitre_check()
```

Im now stuck short of downgrading our app to use sqlalchemy v1 and stop using 
SQLModel which we dont really want to do. 

GitHub link: 
https://github.com/apache/airflow/discussions/44812#discussioncomment-11522177

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]

Reply via email to