forked from distributed-system-analysis/pbench
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the SQL constraint violation logic (distributed-system-analysis#3528
) * Fix the SQL constraint violation logic PBENCH-1251 This is mostly a fix for the ops review problem discovered Thursday, that our carefully unit-tested logic to decode SQLAlchemy `IntegrityError` instances to identify the specific violated constraint (specifically, duplicate vs null) doesn't work in a production environment. The root problem is that the text strings reported differ between the unit test environment (`sqlite3` engine) and the production environment (`postgresql` engine). In order to consolidate on the central constraint error decoder, (which was why this wasn't done earlier), we need all SQL-related exception constructors to be consistent, but I didn't like dropping all context-specific arguments. Instead I've adopted a `**kwargs` model where the decoder passes through arbitrary parameters, which are captured in the exception to provide context. This also adopts a more "pythonic exception" model where `e.args` captures a statically formatted message string and allows the base `Exception.__str__` to provide formatting. I've done this for all the SQLAlchemy model objects, but nowhere else. And to avoid complication in many places where we use `str(exception)`, I'm not including the `kwargs` or raw `cause` in the `args` tuple. I played with that idea, but since `Exception.__str__` formats the entire tuple, the results are ugly and also more difficult to meaningfully compare in tests. We use `str(exception)` a lot both internally and in tests.
- Loading branch information
Showing
15 changed files
with
346 additions
and
405 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.