Enforce required-field completeness when transitioning a record to Public #16
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
db::catalog::set_object_fieldsintentionally does not enforce required-field completeness — a caller may set any subset. Its doc comment notes that completeness "belongs to the publish gate (when moving toVisibility::Public)". Plan 7 built the stepwise transition machine but deferred this gate to keep scope tight.What to do
When transitioning a record to
Visibility::Public(inset_visibility, or a dedicated publish path), validate that everyFieldDefinitionwithrequired = truehas a present value on the object. Reject the publish with a clear error listing the missing required fields if not.Open questions
db::catalog::set_visibility(so every caller is protected) or at the service/API layer?References
crates/db/src/catalog.rs—set_object_fieldsdoc comment;set_visibilitydomain::FieldDefinition { required, .. }docs/plans/2026-06-02-publishing-public-api.md(Notes for follow-on plans)Implemented and merged to
main(e96f74f, no-op fix8cfcf07).Decisions (the issue's open questions):
db::catalog::set_visibility— every caller is protected and the check is atomic with the transition (integrity-critical logic stays indb).object_number,object_name,number_of_objects) are alreadyNOT NULLin0003_object.sql; the other typed columns are optional. So the gate covers field definitions withrequired = true, verifying each key is present and non-null in the object'sfieldsJSONB.Behaviour:
Publicwith missing required fields →VisibilityError::MissingRequiredFields(keys); the admin publish endpoint maps it to 422, and the transition is rejected (visibility unchanged, no audit).Tests:
dbreject-then-succeed round-trip + the re-set no-op;apireal-HTTP 422 with visibility unchanged. Full workspace green.Note: the response is a bare 422 (consistent with the other admin validation errors, which also don't return a structured body). The db error variant carries the missing-key list; surfacing it in the response body — across all the admin 422 paths — would be a worthwhile separate enhancement. Closing.