casper-voltgoed opened a new issue, #31509:
URL: https://github.com/apache/airflow/issues/31509

   ### Apache Airflow version
   
   2.6.1
   
   ### What happened
   
   I am unable to delete users via the "delete command".
   
   I am trying to create a new user delete the default admin user. so I tried 
running the command `airflow users delete -u admin`. Running this command gave 
the following error output:
   ```
   Feature not implemented,tasks route disabled
   
   /usr/local/lib/python3.10/site-packages/flask_limiter/extension.py:293 
UserWarning: Using the in-memory storage for tracking rate limits as no storage 
was explicitly specified. This is not recommended for production use. See: 
https://flask-limiter.readthedocs.io#configuring-a-storage-backend for 
documentation about configuring the storage backend.
   
/usr/local/lib/python3.10/site-packages/astronomer/airflow/version_check/update_checks.py:440
 UserWarning: The setup method 'app_context_processor' can no longer be called 
on the blueprint 'UpdateAvailableView'. It has already been registered at least 
once, any changes will not be applied consistently.
   Make sure all imports, decorators, functions, etc. needed to set up the 
blueprint are done before registering it.
   This warning will become an exception in Flask 2.3.
   /usr/local/lib/python3.10/site-packages/flask/blueprints.py:673 UserWarning: 
The setup method 'record_once' can no longer be called on the blueprint 
'UpdateAvailableView'. It has already been registered at least once, any 
changes will not be applied consistently.
   Make sure all imports, decorators, functions, etc. needed to set up the 
blueprint are done before registering it.
   This warning will become an exception in Flask 2.3.
   /usr/local/lib/python3.10/site-packages/flask/blueprints.py:321 UserWarning: 
The setup method 'record' can no longer be called on the blueprint 
'UpdateAvailableView'. It has already been registered at least once, any 
changes will not be applied consistently.
   Make sure all imports, decorators, functions, etc. needed to set up the 
blueprint are done before registering it.
   This warning will become an exception in Flask 2.3.
   
/usr/local/lib/python3.10/site-packages/airflow/www/fab_security/sqla/manager.py:151
 SAWarning: Object of type <Role> not in session, delete operation along 
'User.roles' won't proceed
   
   [2023-05-24T12:34:19.438+0000] {manager.py:154} ERROR - Remove Register User 
Error: (psycopg2.errors.ForeignKeyViolation) update or delete on table 
"ab_user" violates foreign key constraint "ab_user_role_user_id_fkey" on table 
"ab_user_role"
   DETAIL:  Key (id)=(4) is still referenced from table "ab_user_role".
   
   [SQL: DELETE FROM ab_user WHERE ab_user.id = %(id)s]
   [parameters: {'id': 4}]
   (Background on this error at: https://sqlalche.me/e/14/gkpj)
   Failed to delete user
   ```
   
   Deleting via the UI works fine.
   The error also occurs for users that have a different role, such as Viewer.
   
   ### What you think should happen instead
   
   No error should occur and the specified user should be deleted.
   
   ### How to reproduce
   
   Run a Dag with a task that is a BashOperator that deletes the user e.g.:
   ```python
       remove_default_admin_user_task = 
BashOperator(task_id="remove_default_admin_user",
                                                     bash_command="airflow 
users delete -u admin")
   ```
   
   ### Operating System
   
   Docker containers run in Debian 10
   
   ### Versions of Apache Airflow Providers
   
   Astronomer
   
   ### Deployment
   
   Astronomer
   
   ### Deployment details
   
   I use Astronomer 8.0.0
   
   ### Anything else
   
   Always. It also occurs when ran inside the webserver docker container or 
when ran via the astro CLI with the command `astro dev run airflow users delete 
-u admin`.
   
   ### Are you willing to submit PR?
   
   - [ ] 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