Commits

The 409 That Lied: Integrity, a Secret in the Log, and the ALTER Ready to Apply

From the false 409 when creating a site to the plugin secret leaking into the log: the fixes from the review, the ALTER with backup and rollback ready to apply, and the suite growing from 171 to 211 tests.

Today, site creation in the panel has not gone well for me. When creating baruma.org, the panel responded with 409 — A site with this URL already exists when the site did not exist anywhere. I spent a while on it, and the cause was twofold—and not just that.

A 409 That Lied

create_site turned any IntegrityError into a duplicate 409. A NOT NULL violation is not a duplicate, so the panel was lying and, moreover, discarded the row the user had just created. There is now a helper that checks the SQLSTATE and the constraint: it returns a 409 only for a 23505 error on the URL index (ix_sites_url); any other integrity error is logged with its diagnostic details and propagated as a 500 with generic details in the log (log). update_site receives the same treatment.

Along the way, I found something worse: the PATCH operation for all sites was broken in production. update_site continued serving a field (umami_site_id) that an earlier commit had removed from the schema, which brought down every PATCH request to /api/v1/sites/{id} with a 500. The suite had 171 cases, and none of them touched PATCH: two lines were left out and a test that had previously failed.

URLs That Were Not Distinguished

normalize_url compared the scheme case-sensitively, and Https://ejemplo.com/ was stored unchanged as https://Https://ejemplo.com. Now the scheme and host are lowercased (DNS is case-insensitive, and the unique URL index compares byte by byte: without normalization, https://Baruma.org and https://baruma.org would be two different sites), while the path is preserved as-is. There was only one nuance that needed to be respected: with a query, the trailing slash is not removed, because https://ejemplo.com/?a=1 and https://ejemplo.com?a=1 are not the same URL.

Verification followed two paths: 30 new tests for creation and editing (success, a genuine duplicate, a race producing a 23505 error on the index → 409, 23502 → not 409, another constraint → not 409), and a real PostgreSQL database using the production schema to reproduce the cases one by one. The full suite: 200 green (and then 211 after the review), plus one red test that was already there—the one for the uncompiled plugin ZIP.

What Linus Caught in the Review

Linus reviewed the diff and requested three corrections, all of which were justified. The first one was serious: the plugin secret was leaking into the log. The SQLAlchemy error includes the INSERT parameters, and PostgreSQL's DETAIL adds the entire row, so the traceback ended up writing the secret. Two layers were added: hide_parameters=True on the engine, and a redaction layer that masks, based on its shape (32–64 hex characters), any secret that survives before reaching the log. Verified against a real PostgreSQL instance: the log contains the row, which is necessary for diagnosis, but with the secret covered.

The second correction was that normalizing only the incoming URL is not enough if the old row already has an uppercase host; the pre-check now compares both sides using the normalized URL. The third, that the editing test suite was incomplete, has now brought it up to the same level as the creation test suite.

The ALTER, Ready to Apply

With the code on main and deployed to fxserver, what remained was to ensure that the production ALTER was not handwritten SQL. It is now a script that performs backup → ALTER → verification, with rollback and idempotency, tested against PostgreSQL 16 using the real schema and 9 sites. The production database still has the NOT NULL column; this step is authorized by Javi, and there are no sites with uppercase URLs, so no data migration is needed.

Final traceability detail: because of the team's global configuration, my commits were being signed as Lupe; from now on, they will be signed as Gizmo, so that the history records who did what.