Skip to content

Capture Integrity Error when adding permission, roles etc#21517

Closed
ephraimbuddy wants to merge 2 commits intoapache:mainfrom
astronomer:handle-duplicate-db-entry-webserver
Closed

Capture Integrity Error when adding permission, roles etc#21517
ephraimbuddy wants to merge 2 commits intoapache:mainfrom
astronomer:handle-duplicate-db-entry-webserver

Conversation

@ephraimbuddy
Copy link
Contributor

I think we shouldn't error when there's an integrity error while adding permission, roles etc.
Warnings should be better or not warn at all, because this error comes up because we are adding an already existing item.

Another option would be to make sure that an object doesn't exist before adding it?


^ Add meaningful description above

Read the Pull Request Guidelines for more information.
In case of fundamental code change, Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in UPDATING.md.

I think we shouldn't error when there's an integrity error while adding permission, roles etc.
Warnings should be better or not warn at all, because this error comes up because we are adding an already existing item.

Another option would be to make sure that an object doesn't exist before adding it?
@boring-cyborg boring-cyborg bot added the area:webserver Webserver related Issues label Feb 11, 2022
@ashb
Copy link
Member

ashb commented Feb 11, 2022

How is it possible to trigger this behaviour?

This feels like it would be better captured in the web layer than the "model" layer, but in the case of FAB that might not be possible.

@ephraimbuddy
Copy link
Contributor Author

How is it possible to trigger this behaviour?

It doesn't happen all the time but I have seen it several times when I stop and start the webserver in breeze.
You can try this way:

  • breeze stop
  • breeze --backend postgres
  • airflow db reset
  • airflow webserver

@ephraimbuddy
Copy link
Contributor Author

I got the error again:

[2022-02-10 21:45:58,686] {manager.py:570} ERROR - Add Permission to Role Error: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "ab_permission_view_role_permission_view_id_role_id_key"
DETAIL:  Key (permission_view_id, role_id)=(109, 1) already exists.

[SQL: INSERT INTO ab_permission_view_role (id, permission_view_id, role_id) VALUES (nextval('ab_permission_view_role_id_seq'), %(permission_view_id)s, %(role_id)s) RETURNING ab_permission_view_role.id]
[parameters: {'permission_view_id': 109, 'role_id': 1}]
(Background on this error at: http://sqlalche.me/e/14/gkpj)
[2022-02-10 21:45:58,689] {manager.py:570} ERROR - Add Permission to Role Error: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "ab_permission_view_role_permission_view_id_role_id_key"
DETAIL:  Key (permission_view_id, role_id)=(109, 1) already exists.

[SQL: INSERT INTO ab_permission_view_role (id, permission_view_id, role_id) VALUES (nextval('ab_permission_view_role_id_seq'), %(permission_view_id)s, %(role_id)s) RETURNING ab_permission_view_role.id]
[parameters: {'permission_view_id': 109, 'role_id': 1}]
(Background on this error at: http://sqlalche.me/e/14/gkpj)
[2022-02-10 21:46:00,497] {security.py:408} INFO - Deleted 1 faulty permissions
/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/persistence.py:1461 SAWarning: DELETE statement on table 'ab_permission_view' expected to delete 1 row(s); 0 were matched.  Please set confirm_deleted_rows=False within the mapper configuration to prevent this warning.
[2022-02-10 21:46:00,512] {security.py:408} INFO - Deleted 1 faulty permissions

return role
except IntegrityError as e:
log.warning(c.LOGMSG_ERR_SEC_ADD_ROLE.format(str(e)))
self.get_session.rollback()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are already catching the Exception on L250 which should also take care of catching IntegrityError

@ephraimbuddy ephraimbuddy deleted the handle-duplicate-db-entry-webserver branch March 23, 2022 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:webserver Webserver related Issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants