SEP-1707: Make override-row lookup canonical-key-aware in the DELETE and PATCH settings-override paths - #1344
SEP-1707: Make override-row lookup canonical-key-aware in the DELETE and PATCH settings-override paths#1344peter-o-addo wants to merge 9 commits into
Conversation
1. Read path already sees a legacy rowINSERT INTO settingoverride (created_at, setting_class, key, value, is_active)
VALUES (datetime('now'), 'SETTINGS', 'pmm__ENDPOINT', '"https://stale.example.com"', 1);GET /api/sep/admin/settings/Settings/PMM__endpoint200 {
"setting_class": "Settings",
"key": "PMM__endpoint",
"value": "https://127.0.0.1:9090",
"has_override": true,
"reload": "hot"
}
2. DELETE removes the legacy row (was a silent 204 that left the row)DELETE /api/sep/admin/settings/Settings/PMM__endpoint204 SELECT COUNT(*) FROM settingoverride
WHERE setting_class='SETTINGS' AND key='pmm__ENDPOINT';
-- 03. DELETE removes both spellingsINSERT INTO settingoverride (created_at, setting_class, key, value, is_active)
VALUES
(datetime('now'), 'SETTINGS', 'pmm__ENDPOINT', '"https://legacy.example.com"', 1),
(datetime('now'), 'SETTINGS', 'PMM__endpoint', '"https://canonical.example.com"', 1);DELETE /api/sep/admin/settings/Settings/PMM__endpoint204 — 4. PATCH updates the legacy row (no duplicate)Seeded only PATCH /api/sep/admin/settings/Settings
{"PMM__endpoint": "https://pmm.example.com"}200 [{
"setting_class": "Settings",
"key": "PMM__endpoint",
"value": "https://pmm.example.com",
"has_override": true
}]One row, same id, stored key left as |
There was a problem hiding this comment.
Pull request overview
This PR fixes a legacy-compatibility gap in the settings-override write paths by making DELETE and PATCH resolve override rows using canonicalized nested keys, so mixed-case historical rows are found and updated/deleted instead of being skipped or duplicated.
Changes:
- Added a registry helper to resolve override rows whose stored key canonicalizes to a requested key.
- Updated DELETE to remove all matching rows (including duplicates) and PATCH to update matching legacy rows rather than inserting a second row.
- Added test coverage for the helper and the HTTP DELETE/PATCH behaviors, plus a changelog fragment.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
app/core/settings_override/registry.py |
Adds override_rows_for_key() to resolve rows by canonicalized key equivalence. |
app/core/settings_override/api/routes.py |
Switches DELETE and PATCH persistence logic to operate on canonical-key-matched rows (including duplicates). |
tests/app/core/settings_override/test_registry.py |
Unit tests for override_rows_for_key() across legacy casing, duplicates, class filtering, inactive rows, and top-level behavior. |
tests/app/core/settings_override/api/test_policy_lockdown.py |
HTTP tests covering DELETE/PATCH against legacy-cased and duplicate stored rows. |
changelog.d/SEP-1707.fixed.md |
Release note describing the behavior change. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| await SettingsOverrideManager.delete_where( | ||
| session, | ||
| col(SettingOverride.key).in_({row.key for row in rows}), | ||
| setting_class=setting_class, | ||
| ) |
| for key, value in to_apply: | ||
| stored_value = unwrap_secrets_for_storage(value) | ||
| existing = await SettingsOverrideManager.first( | ||
| session, setting_class=setting_class, key=key | ||
| existing_rows = await override_rows_for_key( | ||
| session, | ||
| settings_cls=settings_cls, | ||
| setting_class=setting_class, | ||
| key=key, | ||
| ) |
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Summary
Make DELETE and PATCH settings-override paths resolve rows by canonicalizing the stored key, so a legacy mixed-case override is seen, deleted, or updated instead of being skipped or duplicated.
app/core/settings_override/registry.py: addoverride_rows_for_key, which lists a class's rows and keeps those whose stored key canonicalizes to the requested key.app/core/settings_override/api/routes.py: DELETE finds and removes every matching row (including duplicates); PATCH updates matching legacy rows instead of inserting a second one.changelog.d/SEP-1707.fixed.md: add the release-note fragment.Tested
/api/sep/admin/settings/Settings/PMM__endpointafter insertingpmm__ENDPOINTreturns 200 withhas_override: true./api/sep/admin/settings/Settings/PMM__endpointreturns 204 and removes thepmm__ENDPOINTrow.pmm__ENDPOINTandPMM__endpointpresent returns 204 and clears both rows.{"PMM__endpoint": "https://pmm.example.com"}returns 200, keeps a single row, and updates the legacypmm__ENDPOINTvalue in place.Checklist
make test)make run-pre-commit)make makemigrations)changelog.d/if the change is user-facing (make changelog-add), or confirmed N/A (internal-only change, or a same-release-cycle fix for an unreleased sibling ticket)