GitHub user jlandercy created a discussion: Command airflow db clean does not 
work anymore with BashOperator in Airflow 3+

I use Airflow 3.1.0 with Docker Compose (official file).
I would like to automatize Airflow cleaning using Airflow.

If I had to make it by hand, I would open the worker container: 

`docker exec -it airflow-airflow-worker-1 bash`

And issue the following command:

`airflow db clean --clean-before-timestamp 20250930 --yes`

I can also confirm the container does know the connection string:

```
echo $AIRFLOW__DATABASE__SQL_ALCHEMY_CONN
postgresql+psycopg2://airflow:secret@postgres/airflow
```

Anyway when I run this command using a `BashOperator`:

```
    clean_database = BashOperator(
        task_id="clean-database",
        bash_command=f'airflow db clean --clean-before-timestamp 
{clean_before.isoformat()} --yes',
    )
```

I get the following error:

`sqlalchemy.exc.ArgumentError: Could not parse SQLAlchemy URL from string 
'airflow-db-not-allowed:///'`

Which seems to be an explicit forbidden with a volontary bad shaped connection 
string.
I have not found any relevant documentation about this error.

I have confirmed that the `BashOperator` does execute within the same container 
`airflow-airflow-worker-1`.

My question is why my `BashOperator` blocked when issuing this command and how 
can I configure it properly to make it work ?

Related question I opened on SO: 
https://stackoverflow.com/questions/79779432/how-can-i-run-airflow-db-clean-command-using-bashoperator-with-airlfow-3


GitHub link: https://github.com/apache/airflow/discussions/56281

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

Reply via email to