-
Notifications
You must be signed in to change notification settings - Fork 14.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(security): Clean up session/commit logic #29381
Conversation
if deleted_count := pvms.delete(): | ||
logger.info("Deleted %i faulty permissions", deleted_count) | ||
self.get_session.commit() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not really sure what's going on here. The commit was after a SELECT
as opposed to the DELETE
.
@@ -1047,9 +1047,6 @@ def sync_role_definitions(self) -> None: | |||
) | |||
|
|||
self.create_missing_perms() | |||
|
|||
# commit role and view menu updates | |||
self.get_session.commit() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The create_missing_perms
logic already commits.
if self.is_admin(): | ||
return | ||
orig_resource = db.session.query(resource.__class__).get(resource.id) | ||
orig_resource = self.get_session.query(resource.__class__).get(resource.id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use the Flask-AppBuilder session everywhere for consistency. Note that db.session
and self.get_session
are the same Flask-SQLAlchemy session so the logic remains unchanged.
SUMMARY
A few housekeeping tasks with regards to the security manager:
get_session
method is a property and thusget_session()
actually unnecessarily instantiates a new session.add_permission_view_menu
function commits (which is called bymerge_pv
) and thus there's no need to re-commit.Note many of the existing commits could likely be also removed as we have a tendency of over commiting. I'm hoping to tackle that as part of SIP-99B by way of transactions.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION