Skip to content

Fix: saving an existing private key returned a 500 - #57

Merged
jefryelb merged 1 commit into
mainfrom
feature/fotos-write-role
Oct 18, 2026
Merged

jefryelb merged 1 commit into
mainfrom
feature/fotos-write-role

Conversation

@jefryelb

@jefryelb jefryelb commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR

Saving a private key that already exists always failed with a 500. This PR makes the save replace the existing record. It's a one-line fix plus a regression test.

Context

The private store (private table, added in 3b0b6da) holds small admin-managed JSON content such as hordes_join. Admins edit it in /admin → Private: load the key, edit the JSON, click Save. Each save sends the whole JSON document again.

set_private_record used freetser's store.add, which only inserts. When the key already has a row, it raises EntryAlreadyExists, which surfaces as a 500. So:

  • the first save of a key worked;
  • every later save of that key failed, so admins could never update content after creating it.

The handler clearly intended updates (admin_set_private_handler reads the existing record to keep its role). Only the storage call was wrong, and no test saved a key twice.

Fix

set_private_record now uses store.overwrite, which inserts the row if it's missing and replaces it otherwise. freetser provides it for exactly this case.

Verification

  • New tests/test_private_kv.py saves hordes_join twice through /admin/private_kv/set/. The second save returns 200, keeps the read role, and members read the new value. Without the fix, the second save returns a 500.
  • uv run ty check, uv run ruff format and uv run ruff check all pass. uv run pytest: 44 passed, 2 skipped.
  • Running the tests on macOS: run them as BACKEND_PRIVATE_LOCALHOST=1 FAROE_PRIVATE_HOST=127.0.0.1 uv run pytest.

Note

This PR first contained a larger change: letting committees write through the private store. That work moved to #58, which gives committees their own tables. This PR now holds only the bug fix found along the way: one commit, two files.

🤖 Generated with Claude Code

@jefryelb jefryelb closed this Oct 17, 2026
@jefryelb jefryelb changed the title Let committees edit private KV data (FOCUS edits Het Fotoboek) + fix saving existing keys Let committees edit their own private data (FOCUS edits Het Fotoboek) + fix saving existing keys Oct 17, 2026
@jefryelb jefryelb reopened this Oct 17, 2026
@jefryelb jefryelb changed the title Let committees edit their own private data (FOCUS edits Het Fotoboek) + fix saving existing keys Fix: saving an existing private key returned a 500 Oct 17, 2026
set_private_record used store.add, which only inserts: for a key that
already has a row it raises EntryAlreadyExists, so admins could create a
private key (e.g. hordes_join) once but every later save in the admin
Private tab failed with a 500. Use store.overwrite, which inserts or
replaces. Adds a regression test that saves the same key twice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jefryelb
jefryelb force-pushed the feature/fotos-write-role branch from 0fd3708 to b9b341e Compare October 17, 2026 12:25
@jefryelb

Copy link
Copy Markdown
Contributor Author

✅ Tested on demo (2026-10-17)

Deployed to demo.dsavdodeka.nl together with #58. For the test window, both PRs were merged into a temporary branch, which has since been deleted.

Check Result
In /admin → Private, save a new key (test_pr57) ✅ "Saved."
Save the same key a second time with a new value: this used to fail with a 500 ✅ "Saved."; /admin/private_kv/get/ returns the new value and keeps the read role member

Afterwards the server was restored. ~/dodeka is back on main and demo was restarted on main. Production was not restarted during the test.

@jefryelb
jefryelb requested a review from tiptenbrink October 17, 2026 16:54
@jefryelb
jefryelb merged commit a50142d into main Oct 18, 2026
2 checks passed
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.

2 participants