Skip to content

fix: keep stored metadata when a project, group or user update does not set it - #2058

Open
rohilsurana wants to merge 5 commits into
mainfrom
fix/keep-metadata-on-update
Open

rohilsurana wants to merge 5 commits into
mainfrom
fix/keep-metadata-on-update

Conversation

@rohilsurana

Copy link
Copy Markdown
Member

Fixes #2030.

Problem

Updating a project, group or user replaced the whole metadata column with what the request sent.
If a client left metadata out, the stored keys were wiped.
#2019 fixed this for organizations. This PR does the same for project, group and user.

UpdateCurrentUser already skipped metadata when it was not set.
But the repository then wrote JSON null over the stored value, so it lost data too.

What changed

  • Handlers (UpdateProject, UpdateGroup, UpdateUser, UpdateCurrentUser) read metadata only when the request sets it.
  • Schema validation runs only when metadata is set.
  • Each repository update method leaves the metadata column alone when metadata is nil.
    • project: UpdateByID, UpdateByName
    • group: UpdateByID
    • user: UpdateByID, UpdateByEmail, UpdateByName

Behavior

  • Metadata not set: the stored metadata stays.
  • Metadata set: it replaces the stored value.
  • Metadata set to {}: the stored metadata is cleared.

Behavior change for API clients

  • Clients that left metadata out to clear it must now send {}.
  • User update by name used to ignore an empty map. Now {} clears metadata, the same as the other update paths.

Tests

  • Handler tests for: not set, set, and set to {}.
  • Repository tests for every update method: keeps, replaces, clears.
  • E2e tests for project, group, user by id, and current user.
  • make lint is clean. Unit, repository and the full e2e regression suite pass.

@vercel

vercel Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
frontier Ready Ready Preview Nov 23, 2026 6:36am UTC

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Updating a group, project, or user without specifying metadata now preserves existing metadata instead of clearing it.
    • Updates with metadata replace existing values, while explicitly providing empty metadata clears it.
    • Invalid metadata continues to be rejected, including in current-user updates.

Update handlers for groups, projects, and users now distinguish omitted metadata from supplied metadata. PostgreSQL updates preserve stored metadata when it is omitted and replace it when supplied. Tests cover omission, replacement, and clearing.

Changes: Metadata update behavior

Layer / File(s) Summary
Handler metadata presence
internal/api/v1beta1connect/group.go, internal/api/v1beta1connect/group_test.go, internal/api/v1beta1connect/project.go, internal/api/v1beta1connect/project_test.go, internal/api/v1beta1connect/user.go, internal/api/v1beta1connect/user_test.go
Handlers pass nil metadata when the request omits the field. When metadata is supplied, handlers build and validate it. Tests cover omitted and explicitly empty metadata.
Repository metadata writes
internal/store/postgres/group_repository.go, internal/store/postgres/group_repository_test.go, internal/store/postgres/project_repository.go, internal/store/postgres/project_repository_test.go, internal/store/postgres/user_repository.go, internal/store/postgres/user_repository_test.go
Repository updates omit the metadata column for nil values and write non-nil values, including empty maps. Tests cover preservation, replacement, and clearing.
End-to-end metadata updates
test/e2e/regression/group_metadata_test.go, test/e2e/regression/project_metadata_test.go, test/e2e/regression/user_metadata_test.go
Regression tests check that omitted metadata is preserved, supplied metadata replaces it, and empty metadata clears it for groups, projects, and users.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • raystack/frontier#2019: It applies the same omitted-versus-supplied metadata update behavior to organizations.

Suggested reviewers: amangit07, rohanchkrabrty

Merge Risk: Minimal · up to 260c1

Project, group, and user updates now keep stored metadata when a request omits it, and sending an empty object clears it. Tests cover the omitted, replaced, and cleared cases. No merge-blocking risk was identified.

Pre-merge checks: Passed 2

Check name Status Explanation
Linked Issues check Passed Directly linked issue #2030 has four coding requirements: (1) omitted metadata keeps stored values and skips schema validation, (2) supplied metadata replaces stored values, (3) supplied {} clears the…
Out of Scope Changes check Passed All reported changes map to #2030. Handler changes in project.go, group.go, user.go and their tests implement the omitted, set, and {} cases. Repository changes in the project, group, and user reposit…
Full details: Linked Issues check

Explanation

Directly linked issue #2030 has four coding requirements: (1) omitted metadata keeps stored values and skips schema validation, (2) supplied metadata replaces stored values, (3) supplied {} clears them, (4) handler, repository, and e2e tests cover these cases. Handler evidence (supplied summary): UpdateProject, UpdateGroup, UpdateUser, and UpdateCurrentUser call metadata.BuildFromProto and run schema validation only when the request sets metadata. Omitted metadata passes nil to the service. Repository evidence (supplied summary): buildProjectUpdateColumns, buildGroupUpdateColumns, and buildUserUpdateColumns add the metadata column only when the Go value is non-nil. User UpdateByName now clears metadata on {}, as #2030 requires. Tests (supplied summary): handler tests for the three cases in project, group, and user; repository tests TestUpdateMetadataHandling for each update method; e2e tests TestUpdateProjectMetadata, TestUpdateGroupMetadata, and TestUpdateUserMetadata. The repository diffs could not be read because changed blobs are missing from the checkout, so the repository conclusions rest on the supplied summary. Title and avatar behavior is excluded by #2030 and is not required here.

Full details: Out of Scope Changes check

Explanation

All reported changes map to #2030. Handler changes in project.go, group.go, user.go and their tests implement the omitted, set, and {} cases. Repository changes in the project, group, and user repositories implement the nil-skip behavior for metadata. Repository tests and e2e regression tests cover the same three cases. The user UpdateByName change is required by #2030, which names that path. No title, avatar, or unrelated behavior change appears in the supplied evidence. Title and avatar stay replaced when omitted, as #2030 places them out of scope. Repository diffs were not readable, so this conclusion partly rests on the supplied summary. Coverage gaps reported by Coveralls do not count as out-of-scope changes.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 4759837 and 260c116.

Files selected for processing: 2

  • test/e2e/regression/project_metadata_test.go
  • test/e2e/regression/user_metadata_test.go

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@rohilsurana

Copy link
Copy Markdown
Member Author

Sandbox API run

I ran 60 API cases against a local Frontier sandbox: Postgres and SpiceDB in Docker, with the server built from each commit.
Both builds used the same database.

  • This branch: all 60 pass.
  • main at f38ac11: 16 fail. These are the cases where an update without metadata wipes the stored value, plus the strict schema and {} by name cases.
  • The other 44 pass on both. They cover create, get, list, title updates, schema rejection and email checks.

User list APIs do not return metadata on either build, so those cases only check that the user is found.

All 60 cases
# Scenario This branch main
P01 CreateProject: create with metadata returns it pass pass
P02 GetProject: get by id returns created metadata pass pass
P03 GetProject: get by name returns created metadata pass pass
P04 UpdateProject: update by id without metadata keeps stored metadata pass fail
P05 UpdateProject: update by id still changes the title pass pass
P06 UpdateProject: update by id with metadata replaces stored metadata pass pass
P07 UpdateProject: update by id with {} clears stored metadata pass pass
P08 UpdateProject: update by name without metadata keeps stored metadata pass fail
P09 UpdateProject: update by name with metadata replaces stored metadata pass pass
P10 UpdateProject: update by name with {} clears stored metadata pass pass
P11 ListOrganizationProjects: kept metadata shows in org project list pass fail
P12 AdminService/ListProjects: kept metadata shows in admin project list pass fail
P13 ListOrganizationProjects, AdminService/ListProjects: lists return created metadata pass pass
P14 UpdateProject: project has no metaschema so any metadata shape is accepted pass pass
P15 UpdateProject: update of a missing project id is rejected (permission_denied, authz runs first) pass pass
G01 CreateGroup: create with metadata returns it pass pass
G02 GetGroup: get returns created metadata pass pass
G03 UpdateGroup: update without metadata keeps stored metadata pass fail
G04 UpdateGroup: update still changes the title pass pass
G05 UpdateGroup: update with metadata replaces stored metadata pass pass
G06 UpdateGroup: update with {} clears stored metadata pass pass
G07 ListOrganizationGroups: kept metadata shows in org group list pass fail
G08 AdminService/ListGroups: kept metadata shows in admin group list pass fail
G09 ListOrganizationGroups, AdminService/ListGroups: lists return created metadata pass pass
G10 UpdateGroup: metadata that breaks the group schema is rejected and nothing changes pass pass
G11 CreateGroup: create with schema-breaking metadata is rejected pass pass
G12 UpdateGroup: nested label object passes the group schema pass pass
G13 GetGroup: get with members still returns kept metadata pass fail
U01 CreateUser: create with metadata returns it pass pass
U02 GetUser: get by id returns created metadata pass pass
U03 GetUser: get by email returns created metadata pass pass
U04 GetUser: get by name returns created metadata pass pass
U05 UpdateUser: update by id without metadata keeps stored metadata pass fail
U06 UpdateUser: update by id still changes the title pass pass
U07 UpdateUser: update by id with metadata replaces stored metadata pass pass
U08 UpdateUser: update by id with {} clears stored metadata pass pass
U09 UpdateUser: update by email without metadata keeps stored metadata pass fail
U10 UpdateUser: update by email with metadata replaces stored metadata pass pass
U11 UpdateUser: update by email with {} clears stored metadata pass pass
U12 UpdateUser: update by name without metadata keeps stored metadata pass pass
U13 UpdateUser: update by name with {} clears stored metadata pass fail
U14 UpdateUser: update by name with metadata replaces stored metadata pass pass
U15 UpdateUser: metadata that breaks the user schema is rejected and nothing changes pass pass
U16 CreateUser: create with schema-breaking metadata is rejected pass pass
U17 UpdateUser: update by email for an unknown user creates it with metadata pass pass
U18 UpdateUser: update by email with a different body email is rejected pass pass
U19 AdminService/ListAllUsers: admin list finds the updated user by keyword pass pass
U20 ListUsers: list finds the updated user by keyword pass pass
U21 ListOrganizationUsers: org member list finds the updated user pass pass
U22 GetUser: kept metadata is visible by id, email and name pass fail
U23 UpdateUser: update without body email is rejected and metadata stays pass pass
C01 UpdateCurrentUser, GetCurrentUser: set metadata on self and read it back pass pass
C02 UpdateCurrentUser: update self without metadata keeps stored metadata pass fail
C03 UpdateCurrentUser: update self still changes the title pass pass
C04 UpdateCurrentUser: update self with metadata replaces, then {} clears pass pass
C05 UpdateCurrentUser: schema-breaking metadata on self is rejected and nothing changes pass pass
C06 GetUser: admin sees metadata kept after a self update pass fail
C07 UpdateCurrentUser: self update with another email is rejected and metadata stays pass pass
S01 UpdateGroup: with a strict group schema, update without metadata skips validation pass fail
S02 UpdateUser: with a strict user schema, update without metadata skips validation pass fail

@coveralls

coveralls commented Nov 20, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 45125195074

Coverage increased (+0.007%) to 56.473%

Details

  • Coverage increased (+0.007%) from the base build.
  • Patch coverage: 14 uncovered changes across 4 files (65 of 79 lines covered, 82.28%).
  • 1 coverage regression across 1 file.

Uncovered Changes

File Changed Covered %
internal/store/postgres/user_repository.go 24 19 79.17%
internal/store/postgres/project_repository.go 20 16 80.0%
internal/store/postgres/group_repository.go 18 15 83.33%
internal/api/v1beta1connect/user.go 7 5 71.43%
Total (6 files) 79 65 82.28%

Coverage Regressions

1 previously-covered line in 1 file lost coverage.

File Lines Losing Coverage Coverage
internal/store/postgres/user_repository.go 1 78.23%

Coverage Stats

Coverage Status
Relevant Lines: 42507
Covered Lines: 24005
Line Coverage: 56.47%
Coverage Strength: 22.09 hits per line

💛 - Coveralls

This branch was successfully deployed

1 active deployment
Preview — 260c1162 Deployed Nov 23, 2026 by vercel[bot]
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.

fix: keep stored metadata when a project, group or user update does not set it

2 participants