-
Notifications
You must be signed in to change notification settings - Fork 9
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
Improve handle_errors
context manager
#657
Merged
Merged
Commits on Aug 10, 2023
-
[web] modify concerns of
handle_errors
1. doing the abort() inside of `handle_errors` is useful, because currently, every call of this context manager resides in a `try: … except PycroftError: return default_response()`-block. 2. The `session.begin_nested()` seems convenient, but just hides something important from the person programming the view. Since in the view, `session.commit()` has to be called explicitly as well, it is only consistent to also call `session.begin_nested()` explicitly. Even more importantly, blindly wrapping the whole cm body in `begin_nested` has two disadvantages: a) It discourages „commit often“, which is favorable to long-running transactions b) It allows you to think `commit` inside this context will just work, while this actually will cause problems in production (undetected in tests, because there `commit()` is a NOP): sqlalchemy disallows committing while in a subtransaction. Thus, it makes more sense to let the user call `begin_nested` explicitly.
Configuration menu - View commit details
-
Copy full SHA for 15573ac - Browse repository at this point
Copy the full SHA 15573acView commit details -
[ci] add semgrep rule for lack of
begin_nested
This will be removed after fixing all the usages
Configuration menu - View commit details
-
Copy full SHA for 8bca177 - Browse repository at this point
Copy the full SHA 8bca177View commit details -
Configuration menu - View commit details
-
Copy full SHA for 4c506f7 - Browse repository at this point
Copy the full SHA 4c506f7View commit details -
Configuration menu - View commit details
-
Copy full SHA for a1e460a - Browse repository at this point
Copy the full SHA a1e460aView commit details -
Configuration menu - View commit details
-
Copy full SHA for 531e910 - Browse repository at this point
Copy the full SHA 531e910View commit details -
[web] move session committing outside
begin_nested()
This will not cause errors to be unhandled, because exiting out of the `begin_nested()` context manager will cause a `flush()`, triggering all of the possible errors that might occur in the transaction.
Configuration menu - View commit details
-
Copy full SHA for 5c7929a - Browse repository at this point
Copy the full SHA 5c7929aView commit details -
Configuration menu - View commit details
-
Copy full SHA for 446820e - Browse repository at this point
Copy the full SHA 446820eView commit details -
Configuration menu - View commit details
-
Copy full SHA for 4feb2e7 - Browse repository at this point
Copy the full SHA 4feb2e7View commit details -
[web] remove unused
web_execute
functionIt has been replaced by the `handle_errors` context manager.
Configuration menu - View commit details
-
Copy full SHA for cbc29d1 - Browse repository at this point
Copy the full SHA cbc29d1View commit details -
Configuration menu - View commit details
-
Copy full SHA for 73b4e31 - Browse repository at this point
Copy the full SHA 73b4e31View commit details
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.