Closed
Bug 1325838
Opened 7 years ago
Closed 6 years ago
Stop using Python asserts for conditions that should be checked in production
Categories
(Tree Management :: Treeherder, defect, P3)
Tree Management
Treeherder
Tracking
(Not tracked)
RESOLVED
FIXED
People
(Reporter: emorley, Assigned: ghickman)
Details
Attachments
(2 files, 1 obsolete file)
`assert` statements are removed depending on the Python optimisation level, so should not be used outside of checks that are intended to be test or debug only. However there are several places where we currently use them, when we should use if statements and explicit raises instead. eg: https://github.com/mozilla/treeherder/search?utf8=%E2%9C%93&q=assert+-path%3Atests%2F&type=Code
Comment 1•7 years ago
|
||
Hey, Is this just a simple case of converting all the asserts to if statements and raising the required exceptions? I'd like to take a look.
Reporter | ||
Comment 2•7 years ago
|
||
Yeah that sounds right :-)
Comment 3•7 years ago
|
||
Alright, I'll try and get this done. Do you only need this changed in the places you mentioned in your initial comment? Some input will be appreciated. (what type of errors to raise etc)
Comment 4•6 years ago
|
||
Reporter | ||
Updated•6 years ago
|
Priority: P2 → P3
Comment 5•6 years ago
|
||
Assignee | ||
Updated•6 years ago
|
Assignee: nobody → ghickman
Assignee | ||
Updated•6 years ago
|
Attachment #8959565 -
Flags: review?(emorley)
Reporter | ||
Updated•6 years ago
|
Attachment #8959565 -
Flags: review?(emorley) → review?(cdawson)
Comment 6•6 years ago
|
||
Commit pushed to master at https://github.com/mozilla/treeherder https://github.com/mozilla/treeherder/commit/8a1fb7befbd30310fb5808bbaf45715ccafd0052 Bug 1325838 - Remove non-testing assert statements (#3348) * Replace settings asserts with ImproperlyConfigured * Replace attribute asserts with AttributeError * Replace duplicate key assert with a custom exception There doesn't seem like a better exception to use here so I added a custom one. * Check the id exists * Replace asserts with manual AssertionErrors
Comment 7•6 years ago
|
||
Comment on attachment 8959565 [details] [review] Link to GitHub pull-request: https://github.com/mozilla/treeherder/pull/3348 Thanks!!
Attachment #8959565 -
Flags: review?(cdawson) → review+
Comment 8•6 years ago
|
||
I noticed a couple other ``assert`` statements in one of our model managers. I'm not clear if those should be converted as well? https://github.com/mozilla/treeherder/blob/5052c5dfaae007011cfb8ec7e025a89b8974263c/treeherder/model/models.py#L1159-L1164 Ed: What do you think?
Flags: needinfo?(emorley)
Reporter | ||
Comment 9•6 years ago
|
||
Yeah let's change those too - something like this from the obsoleted previous PR should work (or whatever else looks better): https://github.com/mozilla/treeherder/pull/3128/files#diff-e432623caa985e5ac4d48814de254a58R1164
Flags: needinfo?(emorley)
Reporter | ||
Updated•6 years ago
|
Attachment #8942245 -
Attachment is obsolete: true
Comment 10•6 years ago
|
||
Assignee | ||
Updated•6 years ago
|
Attachment #8960653 -
Flags: review?(cdawson)
Updated•6 years ago
|
Attachment #8960653 -
Flags: review?(cdawson) → review+
Comment 11•6 years ago
|
||
Commit pushed to master at https://github.com/mozilla/treeherder https://github.com/mozilla/treeherder/commit/e6aec72dd9b614c46141930df7c8a797328411de Bug 1325838 - remove asserts in MatcherManager classmethods (#3354)
Updated•6 years ago
|
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•