Skip to content

fix(spp_drims): name constants after codes the vocabulary actually ships - #438

Open
emjay0921 wants to merge 3 commits into
19.0from
fix/1165-drims-constants
Open

fix(spp_drims): name constants after codes the vocabulary actually ships#438
emjay0921 wants to merge 3 commits into
19.0from
fix/1165-drims-constants

Conversation

@emjay0921

Copy link
Copy Markdown
Contributor

Why is this change needed?

Four constants in spp_drims/models/constants.py held values that exist in no shipped vocabulary: PRIORITY_LOW/MEDIUM/HIGH ("low"/"medium"/"high", where the data ships 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 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:

  • 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. 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?

  • Each code constant is now named after the code it holds rather than remapped to the nearest concept — "urgent" is not a medium priority. That gives PRIORITY_ROUTINE/URGENT/CRITICAL and DRIMS_TYPE_INTERNAL_TRANSFER, so a name cannot describe something the data does not have.
  • The file is completed, since a partly declared group is what sends a caller back to hardcoding a string: 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.
  • Three guards: 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.
  • spp.drims.alert.priority is a different field — a Selection of low/medium/high/critical — and its views are correct. Left alone.

New unit tests

spp_drims/tests/test_constants.py — the durable part. CODE_NAMESPACES records which vocabulary each group of code constants draws from, and the test walks it to assert every constant resolves to a real spp.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_drims suite on this branch after merging 19.0 in: 272 tests, 0 failed, 0 errors.

How to test manually

  1. Open DRIMS → Requests and set one request to Urgent and another to Critical.
  2. The list decoration and priority badge now show for those, where High/Medium styling never appeared before.
  3. Use the search panel's priority filters — each returns the matching records instead of nothing.
  4. Check the approval SLA on an Urgent request: 8 hours, not the 24-hour routine default it silently fell back to.
  5. Confirm DRIMS alerts are unaffected — their priority is a separate Selection field and its values are unchanged.

Related links

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
emjay0921 marked this pull request as ready for review August 18, 2026 08:03
@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.25%. Comparing base (0820667) to head (c5946a0).

Additional details and impacted files

Impacted file tree graph

@@           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     
Flag Coverage Δ
spp_base_common 91.07% <ø> (ø)
spp_drims 82.34% <100.00%> (+0.10%) ⬆️
spp_drims_sl_demo 68.43% <ø> (-0.58%) ⬇️
spp_programs 65.27% <ø> (ø)
spp_registry 87.22% <ø> (+0.07%) ⬆️
spp_security 69.56% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
spp_drims/models/constants.py 100.00% <100.00%> (ø)
spp_drims/models/request.py 93.19% <ø> (ø)
spp_drims/models/res_config_settings.py 61.11% <100.00%> (ø)

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant