Skip to content

Commit 8a74908

Browse files
fix: address CI findings — psycopg2.sql composition in migration, regenerate READMEs
Semgrep flagged f-string SQL in the severity migration; identifiers were constants but composed SQL via psycopg2.sql removes the pattern entirely. READMEs regenerated from the updated HISTORY fragments (in-scope modules only).
1 parent a4dd8e8 commit 8a74908

9 files changed

Lines changed: 200 additions & 110 deletions

File tree

spp_drims/README.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@ Dependencies
179179
Changelog
180180
=========
181181

182+
19.0.2.1.0
183+
~~~~~~~~~~
184+
185+
- feat: incident areas expose ``effective_severity_id`` (area override
186+
or incident severity) and a numeric 1-5 ``severity_numeric`` derived
187+
from CAP severity codes for choropleth visualization (re-land from
188+
#76, follows the spp_hazard severity vocabulary change).
189+
182190
19.0.2.0.0
183191
~~~~~~~~~~
184192

spp_drims/static/description/index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,15 @@ <h2><a class="toc-backref" href="#toc-entry-1">Changelog</a></h2>
565565
</div>
566566
</div>
567567
<div class="section" id="section-1">
568+
<h1>19.0.2.1.0</h1>
569+
<ul class="simple">
570+
<li>feat: incident areas expose <tt class="docutils literal">effective_severity_id</tt> (area override
571+
or incident severity) and a numeric 1-5 <tt class="docutils literal">severity_numeric</tt> derived
572+
from CAP severity codes for choropleth visualization (re-land from
573+
#76, follows the spp_hazard severity vocabulary change).</li>
574+
</ul>
575+
</div>
576+
<div class="section" id="section-2">
568577
<h1>19.0.2.0.0</h1>
569578
<ul class="simple">
570579
<li>Initial migration to OpenSPP2</li>

spp_drims_sl_demo/README.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ Dependencies
130130
Changelog
131131
=========
132132

133+
19.0.2.0.1
134+
~~~~~~~~~~
135+
136+
- fix: demo generator resolves scenario severity levels to CAP severity
137+
vocabulary codes (follows the spp_hazard severity vocabulary change,
138+
re-land from #76).
139+
133140
19.0.2.0.0
134141
~~~~~~~~~~
135142

spp_drims_sl_demo/static/description/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,14 @@ <h2><a class="toc-backref" href="#toc-entry-1">Changelog</a></h2>
503503
</div>
504504
</div>
505505
<div class="section" id="section-1">
506+
<h1>19.0.2.0.1</h1>
507+
<ul class="simple">
508+
<li>fix: demo generator resolves scenario severity levels to CAP severity
509+
vocabulary codes (follows the spp_hazard severity vocabulary change,
510+
re-land from #76).</li>
511+
</ul>
512+
</div>
513+
<div class="section" id="section-2">
506514
<h1>19.0.2.0.0</h1>
507515
<ul class="simple">
508516
<li>Initial migration to OpenSPP2</li>

spp_hazard/README.rst

Lines changed: 88 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -312,20 +312,20 @@ Log in as **Admin** or **Manager**.
312312

313313
**3.6 Search and Grouping**
314314

315-
+-------+-------------------------------+------------------------------+
316-
| Step | Action | Expected Result |
317-
+=======+===============================+==============================+
318-
| 3.6.1 | Type in search bar, select | Filters by name |
319-
| | "Name" search | |
320-
+-------+-------------------------------+------------------------------+
321-
| 3.6.2 | Type in search bar, select | Filters by code |
322-
| | "Code" search | |
323-
+-------+-------------------------------+------------------------------+
324-
| 3.6.3 | Use Filters > Active / | Filters correctly |
325-
| | Inactive | |
326-
+-------+-------------------------------+------------------------------+
327-
| 3.6.4 | Use Group By > Parent | Categories grouped by parent |
328-
+-------+-------------------------------+------------------------------+
315+
+-------+------------------------------+------------------------------+
316+
| Step | Action | Expected Result |
317+
+=======+==============================+==============================+
318+
| 3.6.1 | Type in search bar, select | Filters by name |
319+
| | "Name" search | |
320+
+-------+------------------------------+------------------------------+
321+
| 3.6.2 | Type in search bar, select | Filters by code |
322+
| | "Code" search | |
323+
+-------+------------------------------+------------------------------+
324+
| 3.6.3 | Use Filters > Active / | Filters correctly |
325+
| | Inactive | |
326+
+-------+------------------------------+------------------------------+
327+
| 3.6.4 | Use Group By > Parent | Categories grouped by parent |
328+
+-------+------------------------------+------------------------------+
329329

330330
--------------
331331

@@ -365,18 +365,18 @@ Log in as **Admin** or **Manager**.
365365

366366
**4.2 Create an Impact Type**
367367

368-
+-------+----------------------------------+---------------------------+
369-
| Step | Action | Expected Result |
370-
+=======+==================================+===========================+
371-
| 4.2.1 | Click **New** | Form opens |
372-
+-------+----------------------------------+---------------------------+
373-
| 4.2.2 | Enter Name: | Fields accept input |
374-
| | ``Water Contamination``, Code: | |
375-
| | ``WATER_CONTAM``, Category: | |
376-
| | Health | |
377-
+-------+----------------------------------+---------------------------+
378-
| 4.2.3 | Save | Record saves successfully |
379-
+-------+----------------------------------+---------------------------+
368+
+-------+------------------------------+------------------------------+
369+
| Step | Action | Expected Result |
370+
+=======+==============================+==============================+
371+
| 4.2.1 | Click **New** | Form opens |
372+
+-------+------------------------------+------------------------------+
373+
| 4.2.2 | Enter Name: | Fields accept input |
374+
| | ``Water Contamination``, | |
375+
| | Code: ``WATER_CONTAM``, | |
376+
| | Category: Health | |
377+
+-------+------------------------------+------------------------------+
378+
| 4.2.3 | Save | Record saves successfully |
379+
+-------+------------------------------+------------------------------+
380380

381381
**4.3 Reorder via Drag**
382382

@@ -594,17 +594,17 @@ Use the incident created in 5.2 (starts as "Active").
594594

595595
**5.8 Stat Buttons**
596596

597-
+-------+------------------------------+-------------------------------+
598-
| Step | Action | Expected Result |
599-
+=======+==============================+===============================+
600-
| 5.8.1 | Click "Affected" stat button | Opens Impact Records list |
601-
| | | filtered to this incident |
602-
+-------+------------------------------+-------------------------------+
603-
| 5.8.2 | Click browser back | Returns to incident form |
604-
+-------+------------------------------+-------------------------------+
605-
| 5.8.3 | Click "Areas" stat button | Opens Area list filtered to |
606-
| | | linked areas |
607-
+-------+------------------------------+-------------------------------+
597+
+-------+------------------------------+------------------------------+
598+
| Step | Action | Expected Result |
599+
+=======+==============================+==============================+
600+
| 5.8.1 | Click "Affected" stat button | Opens Impact Records list |
601+
| | | filtered to this incident |
602+
+-------+------------------------------+------------------------------+
603+
| 5.8.2 | Click browser back | Returns to incident form |
604+
+-------+------------------------------+------------------------------+
605+
| 5.8.3 | Click "Areas" stat button | Opens Area list filtered to |
606+
| | | linked areas |
607+
+-------+------------------------------+------------------------------+
608608

609609
**5.9 Search and Filters (Incident List)**
610610

@@ -645,24 +645,25 @@ Use the incident created in 5.2 (starts as "Active").
645645

646646
**5.10 List View Decorations**
647647

648-
+--------+----------------------------+--------------------------------+
649-
| Step | Action | Expected Result |
650-
+========+============================+================================+
651-
| 5.10.1 | Check row coloring | Alert rows: blue tint. |
652-
| | | Recovery rows: yellow tint. |
653-
| | | Closed rows: grey/muted. |
654-
| | | Active rows: default (no |
655-
| | | special coloring) |
656-
+--------+----------------------------+--------------------------------+
657-
| 5.10.2 | Check Status column badges | Alert: blue badge. Active: |
658-
| | | green badge. Recovery: yellow |
659-
| | | badge. Closed: grey badge |
660-
+--------+----------------------------+--------------------------------+
661-
| 5.10.3 | Check columns visible | Name, Code, Category, Start |
662-
| | | Date, End Date (optional), |
663-
| | | Status, Severity, Areas, |
664-
| | | Affected |
665-
+--------+----------------------------+--------------------------------+
648+
+--------+------------------------------+------------------------------+
649+
| Step | Action | Expected Result |
650+
+========+==============================+==============================+
651+
| 5.10.1 | Check row coloring | Alert rows: blue tint. |
652+
| | | Recovery rows: yellow tint. |
653+
| | | Closed rows: grey/muted. |
654+
| | | Active rows: default (no |
655+
| | | special coloring) |
656+
+--------+------------------------------+------------------------------+
657+
| 5.10.2 | Check Status column badges | Alert: blue badge. Active: |
658+
| | | green badge. Recovery: |
659+
| | | yellow badge. Closed: grey |
660+
| | | badge |
661+
+--------+------------------------------+------------------------------+
662+
| 5.10.3 | Check columns visible | Name, Code, Category, Start |
663+
| | | Date, End Date (optional), |
664+
| | | Status, Severity, Areas, |
665+
| | | Affected |
666+
+--------+------------------------------+------------------------------+
666667

667668
--------------
668669

@@ -832,22 +833,22 @@ Using the impact created in 6.1 (starts as "Reported"):
832833

833834
**6.7 Impact List Decorations**
834835

835-
+-------+----------------------------+---------------------------------+
836-
| Step | Action | Expected Result |
837-
+=======+============================+=================================+
838-
| 6.7.1 | Check row coloring | Reported: blue. Verified: |
839-
| | | green. Disputed: yellow. |
840-
| | | Closed: grey/muted |
841-
+-------+----------------------------+---------------------------------+
842-
| 6.7.2 | Verification Status badges | Same color coding as rows |
843-
+-------+----------------------------+---------------------------------+
844-
| 6.7.3 | Damage Level column | Shows as badge widget (neutral |
845-
| | | color) |
846-
+-------+----------------------------+---------------------------------+
847-
| 6.7.4 | Optional columns | "Verified By" and "Verified |
848-
| | | Date" available under column |
849-
| | | options (hidden by default) |
850-
+-------+----------------------------+---------------------------------+
836+
+-------+------------------------------+------------------------------+
837+
| Step | Action | Expected Result |
838+
+=======+==============================+==============================+
839+
| 6.7.1 | Check row coloring | Reported: blue. Verified: |
840+
| | | green. Disputed: yellow. |
841+
| | | Closed: grey/muted |
842+
+-------+------------------------------+------------------------------+
843+
| 6.7.2 | Verification Status badges | Same color coding as rows |
844+
+-------+------------------------------+------------------------------+
845+
| 6.7.3 | Damage Level column | Shows as badge widget |
846+
| | | (neutral color) |
847+
+-------+------------------------------+------------------------------+
848+
| 6.7.4 | Optional columns | "Verified By" and "Verified |
849+
| | | Date" available under column |
850+
| | | options (hidden by default) |
851+
+-------+------------------------------+------------------------------+
851852

852853
--------------
853854

@@ -1186,6 +1187,22 @@ encounter unexpected behavior, please report it as a new issue.
11861187
Changelog
11871188
=========
11881189

1190+
19.0.2.1.0
1191+
~~~~~~~~~~
1192+
1193+
- feat: severity is now a CAP v1.2 vocabulary code (``severity_id``,
1194+
``severity_override_id`` on incident areas) instead of a hardcoded 1-5
1195+
Selection; adds CAP urgency/certainty/message-type/event fields, alert
1196+
ingestion (``create_incident_from_alert``), and incident ``uuid``
1197+
(re-land from #76).
1198+
- feat: migration backfills legacy 1-5 severity values onto the
1199+
vocabulary fields when upgrading from 19.0.2.0.x (1→minor, 2→moderate,
1200+
3→severe, 4→severe, 5→extreme); existing values are never overwritten
1201+
and legacy columns are kept.
1202+
- fix: demo incident-area records now set ``severity_override_id``
1203+
vocabulary refs (the removed ``severity_override`` field broke demo
1204+
installs).
1205+
11891206
19.0.2.0.2
11901207
~~~~~~~~~~
11911208

spp_hazard/migrations/19.0.2.1.0/post-migration.py

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import logging
2121

22+
from psycopg2 import sql
23+
2224
# Fixed name: this file is loaded by Odoo's migration runner (and by tests via
2325
# importlib), where __name__ differs; a stable logger keeps output filterable.
2426
_logger = logging.getLogger("odoo.addons.spp_hazard.migrations.severity")
@@ -33,7 +35,7 @@
3335
"5": "extreme",
3436
}
3537

36-
# (table, legacy column, new column) - identifiers are constants, never user input
38+
# (table, legacy column, new column)
3739
TARGETS = [
3840
("spp_hazard_incident", "severity", "severity_id"),
3941
("spp_hazard_incident_area", "severity_override", "severity_override_id"),
@@ -58,19 +60,26 @@ def migrate(cr, version):
5860
_logger.info("spp_hazard severity migration: %s.%s absent, skipping", table, legacy_col)
5961
continue
6062

61-
case_parts = " ".join("WHEN %s THEN %s" for _ in LEGACY_SEVERITY_TO_CAP)
63+
ids = {
64+
"table": sql.Identifier(table),
65+
"legacy": sql.Identifier(legacy_col),
66+
"new": sql.Identifier(new_col),
67+
}
68+
case_parts = sql.SQL(" ").join(sql.SQL("WHEN %s THEN %s") for _ in LEGACY_SEVERITY_TO_CAP)
6269
case_params = [p for pair in LEGACY_SEVERITY_TO_CAP.items() for p in pair]
6370
cr.execute(
64-
f"""
65-
UPDATE {table} t
66-
SET {new_col} = c.id
67-
FROM spp_vocabulary_code c
68-
JOIN spp_vocabulary v ON c.vocabulary_id = v.id
69-
WHERE v.namespace_uri = %s
70-
AND c.code = CASE t.{legacy_col} {case_parts} END
71-
AND t.{legacy_col} IS NOT NULL
72-
AND t.{new_col} IS NULL
73-
""",
71+
sql.SQL(
72+
"""
73+
UPDATE {table} t
74+
SET {new} = c.id
75+
FROM spp_vocabulary_code c
76+
JOIN spp_vocabulary v ON c.vocabulary_id = v.id
77+
WHERE v.namespace_uri = %s
78+
AND c.code = CASE t.{legacy} {case_parts} END
79+
AND t.{legacy} IS NOT NULL
80+
AND t.{new} IS NULL
81+
"""
82+
).format(case_parts=case_parts, **ids),
7483
[CAP_SEVERITY_NS, *case_params],
7584
)
7685
_logger.info(
@@ -81,18 +90,19 @@ def migrate(cr, version):
8190
)
8291

8392
cr.execute(
84-
f"""
85-
SELECT DISTINCT t.{legacy_col}
86-
FROM {table} t
87-
WHERE t.{legacy_col} IS NOT NULL
88-
AND t.{new_col} IS NULL
89-
"""
93+
sql.SQL(
94+
"""
95+
SELECT DISTINCT t.{legacy}
96+
FROM {table} t
97+
WHERE t.{legacy} IS NOT NULL
98+
AND t.{new} IS NULL
99+
"""
100+
).format(**ids)
90101
)
91102
unmapped = [row[0] for row in cr.fetchall()]
92103
if unmapped:
93104
_logger.warning(
94-
"spp_hazard severity migration: %s.%s has unmapped legacy values %s; "
95-
"left empty for manual review",
105+
"spp_hazard severity migration: %s.%s has unmapped legacy values %s; left empty for manual review",
96106
table,
97107
legacy_col,
98108
unmapped,

0 commit comments

Comments
 (0)