fix(spp_drims): name constants after codes the vocabulary actually ships - #438
Open
emjay0921 wants to merge 3 commits into
Open
fix(spp_drims): name constants after codes the vocabulary actually ships#438emjay0921 wants to merge 3 commits into
emjay0921 wants to merge 3 commits into
Conversation
Four constants in constants.py held values present in no shipped
vocabulary: PRIORITY_LOW/MEDIUM/HIGH ("low"/"medium"/"high", where the
data has routine/urgent/critical) and DRIMS_TYPE_TRANSFER ("transfer",
where the code is internal_transfer). Nothing failed, because a search for
a non-existent code returns an empty set rather than raising, so any
comparison against one would simply never match. All four were unused,
which is why it had gone unnoticed; the file still read as the reference
for valid codes.
Rather than remap them to the nearest concept — "urgent" is not a medium
priority — each code constant is now named after the code it holds, so the
name cannot describe something the data does not have. That gives
PRIORITY_ROUTINE/URGENT/CRITICAL and DRIMS_TYPE_INTERNAL_TRANSFER.
Also completes the file, since a partly declared group is what sends a
caller back to hardcoding the string: adds the seven missing codes
(cancelled, fulfilled, critical_shortage, quality_issue, routine, urgent,
internal_transfer) and VOCAB_* constants for the ten vocabularies that had
none, pod-statuses among them.
The durable part is the new test. CODE_NAMESPACES records which vocabulary
each group of code constants draws from, and test_constants.py walks it to
assert every constant resolves to a real spp.vocabulary.code, that every
namespace exists and builds on VOCAB_BASE, and that each name mirrors its
value. Each assertion was checked by reintroducing the defect it guards
against and confirming it fails.
Completeness is asserted only over canonical codes. Covering every code
broke as soon as spp_drims_sl was installed, since it legitimately layers
life_threatening onto priority-levels with is_local set; spp_drims cannot
owe a constant for what a country module adds. A non-local addition still
fails, which is intended.
OP#1165
OP#1165 corrected constants.py but left the places that used the same wrong values as bare strings. The priority-levels vocabulary ships routine, urgent and critical; the views and the SLA lookup still named high, medium and low. - The request list decorated rows and the priority badge on 'high' and 'medium', so those highlights never appeared. - The search panel offered a "High Priority" filter whose domain matched no record, so it always returned nothing. - get_approval_sla_hours was keyed by 'critical', 'high', 'routine', 'low', and the shipped parameters matched. An urgent request found no entry and fell back to the routine default of 24 hours instead of 8 - a wrong answer rather than an error, which is the failure mode this ticket is about. spp.drims.alert.priority is a different field, a Selection of low/medium/high/critical, and its views are correct. Left alone. Three guards added: the SLA hours resolve per shipped priority code, and the list decorations and search filters only name codes that exist. The two view guards fail if the old values come back.
emjay0921
marked this pull request as ready for review
August 18, 2026 08:03
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 19.0 #438 +/- ##
=======================================
Coverage 72.24% 72.25%
=======================================
Files 419 419
Lines 29813 29832 +19
=======================================
+ Hits 21539 21554 +15
- Misses 8274 8278 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why is this change needed?
Four constants in
spp_drims/models/constants.pyheld values that exist in no shipped vocabulary:PRIORITY_LOW/MEDIUM/HIGH("low"/"medium"/"high", where the data shipsroutine/urgent/critical) andDRIMS_TYPE_TRANSFER("transfer", where the code isinternal_transfer). Nothing failed, because a search for a non-existent code returns an empty set rather than raising, so any comparison against one simply never matched. All four were unused, which is why it went unnoticed — while the file still read as the reference for valid codes (OP#1165).The same wrong values were also hardcoded as bare strings in the places that mattered, which is where users actually felt it:
highandmedium, so those highlights never appeared.get_approval_sla_hourswas keyed bycritical,high,routine,low. An urgent request found no entry and fell back to the routine default of 24 hours instead of 8 — a wrong answer rather than an error, which is the failure mode this ticket is about.How was the change implemented?
PRIORITY_ROUTINE/URGENT/CRITICALandDRIMS_TYPE_INTERNAL_TRANSFER, so a name cannot describe something the data does not have.cancelled,fulfilled,critical_shortage,quality_issue,routine,urgent,internal_transfer) andVOCAB_*constants for the ten vocabularies that had none, pod-statuses among them.spp.drims.alert.priorityis a different field — a Selection oflow/medium/high/critical— and its views are correct. Left alone.New unit tests
spp_drims/tests/test_constants.py— the durable part.CODE_NAMESPACESrecords which vocabulary each group of code constants draws from, and the test walks it to assert every constant resolves to a realspp.vocabulary.code, so a constant naming a code the data lacks fails here rather than silently matching nothing.Unit tests executed by the author
Full
spp_drimssuite on this branch after merging19.0in: 272 tests, 0 failed, 0 errors.How to test manually
Related links