Skip to content

fix(db): handle missing metadata#2121

Merged
dobrac merged 2 commits intomainfrom
fix/no-metadata
Mar 12, 2026
Merged

fix(db): handle missing metadata#2121
dobrac merged 2 commits intomainfrom
fix/no-metadata

Conversation

@jakubno
Copy link
Member

@jakubno jakubno commented Mar 12, 2026

Two layers:

  • DB level to prevent issue during deploy
  • Long term and more general fix in JSON map on code level

Note

Medium Risk
Touches database trigger behavior and jsonb encoding for a shared type, which can affect how metadata is stored/queried across snapshot paths, but the change is narrowly scoped to normalizing null/nil to {}.

Overview
Prevents snapshot metadata writes from failing the NOT NULL constraint by updating the existing fix_snapshots_metadata_json_null() trigger to also coerce SQL NULL to {}, and by teaching types.JSONBStringMap to marshal nil maps as {} (and unmarshal JSON null to an empty map), with tests covering the new serialization behavior.

Written by Cursor Bugbot for commit 81631cd. This will update automatically on new commits. Configure here.

func (m JSONBStringMap) MarshalJSON() ([]byte, error) {
if m == nil {
return []byte("{}"), nil
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MarshalJSON override affects all JSON serialization of JSONBStringMap, not only DB persistence. Any API response structs embedding this type that previously returned null for absent metadata will now return {}. Clients distinguishing null (field absent/not set) from {} (explicitly empty) will see a behavioral change. Worth verifying no external API consumers rely on the null sentinel before merging.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its ok

@jakubno jakubno marked this pull request as ready for review March 12, 2026 14:41
Copy link
Contributor

@dobrac dobrac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:ty:

@dobrac dobrac merged commit f8caf3d into main Mar 12, 2026
37 checks passed
@dobrac dobrac deleted the fix/no-metadata branch March 12, 2026 18:07
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.

3 participants