Skip to content
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

Merged
merged 2 commits into from
Jun 26, 2024

Conversation

john-bodley
Copy link
Member

@john-bodley john-bodley commented Jun 26, 2024

SUMMARY

A few housekeeping tasks with regards to the security manager:

  1. The Flask-AppBuilder get_session method is a property and thus get_session() actually unnecessarily instantiates a new session.
  2. There's a pattern of over committing. Note that the Flask-AppBuilder add_permission_view_menu function commits (which is called by merge_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

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

if deleted_count := pvms.delete():
logger.info("Deleted %i faulty permissions", deleted_count)
self.get_session.commit()
Copy link
Member Author

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()
Copy link
Member Author

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)
Copy link
Member Author

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.

@john-bodley john-bodley marked this pull request as ready for review June 26, 2024 17:00
@dosubot dosubot bot added the change:backend Requires changing the backend label Jun 26, 2024
@rusackas rusackas added the review:checkpoint Last PR reviewed during the daily review standup label Jun 26, 2024
@john-bodley john-bodley merged commit 466dda2 into master Jun 26, 2024
38 of 61 checks passed
@john-bodley john-bodley deleted the john-bodley--security-cleanup branch June 26, 2024 19:57
@john-bodley john-bodley removed the review:checkpoint Last PR reviewed during the daily review standup label Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
change:backend Requires changing the backend size/S
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants