Skip to content

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

Merged
rohilsurana merged 8 commits into
mainfrom
fix/keep-metadata-on-update
Nov 25, 2026
Merged

rohilsurana merged 8 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 24, 2026 4:13pm 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.
    • Providing metadata replaces existing values, while explicitly providing empty metadata clears it.
    • Invalid metadata is rejected, including in current-user updates.
    • Profile updates no longer unintentionally overwrite metadata when changing profile details.

Group, project, and user update handlers now distinguish omitted metadata from supplied metadata. PostgreSQL updates preserve stored metadata when it is omitted and replace it when supplied, including when it is empty. Profile updates build request bodies without metadata.

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 metadata, explicitly empty metadata, and validation of supplied metadata.
Repository metadata writes
internal/store/postgres/metadata_column.go, 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, internal/store/postgres/organization_repository.go
Repository updates omit the metadata column for nil values and write non-nil values, including empty maps. Tests cover preservation, replacement, and clearing. Organization updates also use the shared metadata-column helper.
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.
Profile update payload
web/sdk/client/views/profile/profile-update-body.ts, web/sdk/client/views/profile/profile-update-body.test.ts, web/sdk/client/views/profile/profile-view.tsx
ProfileView builds update bodies from form values and the current user name. Tests check that avatar-only and title updates omit metadata.

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, mabdh

Merge Risk: Minimal · up to b313e

Updates that omit metadata now keep the stored metadata, and sending an empty object clears it. No merge-blocking risk was identified. API clients that relied on omission to clear metadata must now send an empty object.

Pre-merge checks: Passed 1 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Out of Scope Changes check Inconclusive Backend changes map to #2030: handler changes in project.go, group.go, user.go, their tests; repository helpers setMetadataColumn, buildProjectUpdateColumns, buildGroupUpdateColumns, buildUserUpdateCo… Confirm whether the web profile change is needed for #2030, for example to stop the UI from sending unintended fields. If it is, state that link in the PR description and add the web test evidence to the scope. If it is not, move it to a se…
Passed Passed checks: 1 passed

Check name Status Explanation
Linked Issues check Passed Directly linked issue #2030 has these coding requirements: (1) omitted metadata keeps stored values and skips schema validation; (2) supplied metadata replaces stored values; (3) supplied {} clears st…
Full details: Linked Issues check

Explanation

Directly linked issue #2030 has these coding requirements: (1) omitted metadata keeps stored values and skips schema validation; (2) supplied metadata replaces stored values; (3) supplied {} clears stored values; (4) handler, repository, and e2e tests cover these cases. Handlers: UpdateProject, UpdateGroup, UpdateUser, and UpdateCurrentUser build metadata and run schema validation only when the request sets metadata; omitted metadata reaches the service as nil (per the supplied summary, with the project handler tests and user handler tests asserting nil). Repository: the verified file internal/store/postgres/metadata_column.go defines setMetadataColumn, which returns without writing when md is nil, and otherwise JSON-marshals md into the metadata column. Project, group, user, and organization update paths now call this helper (per the summary). User UpdateByName now clears metadata on {}, as #2030 requires. Tests: handler tests for the three cases; TestUpdateMetadataHandling in project, group, and user repository tests; e2e tests TestUpdateProjectMetadata, TestUpdateGroupMetadata, and TestUpdateUserMetadata. Title and avatar stay out of scope, as #2030 states. The repository update-method diffs could not be read directly (changed blobs missing from the checkout), so the per-method conclusions rest on the supplied summary plus the verified helper.

Full details: Out of Scope Changes check

Explanation

Backend changes map to #2030: handler changes in project.go, group.go, user.go, their tests; repository helpers setMetadataColumn, buildProjectUpdateColumns, buildGroupUpdateColumns, buildUserUpdateColumns, and buildOrgUpdateColumns; and the repository and e2e tests. The web changes in web/sdk/client/views/profile/profile-update-body.ts, profile-update-body.test.ts, and profile-view.tsx are not described in the PR description or in #2030. The supplied summary says profile-view.tsx now sends a body built by profileUpdateBody (title, email, avatar, name) instead of all form data. That may reduce unintended fields sent to the API, but the PR text does not state this link to #2030. The web diff could not be read (changed blobs missing from the checkout), so its content and purpose cannot be confirmed.

Resolution

Confirm whether the web profile change is needed for #2030, for example to stop the UI from sending unintended fields. If it is, state that link in the PR description and add the web test evidence to the scope. If it is not, move it to a separate PR. Also make the web diff readable so its content can be verified.

  • 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 260c116 and b313e68.

Files selected for processing: 9

  • internal/api/v1beta1connect/user_test.go
  • internal/store/postgres/group_repository.go
  • internal/store/postgres/metadata_column.go
  • internal/store/postgres/organization_repository.go
  • internal/store/postgres/project_repository.go
  • internal/store/postgres/user_repository.go
  • web/sdk/client/views/profile/profile-update-body.test.ts
  • web/sdk/client/views/profile/profile-update-body.ts
  • web/sdk/client/views/profile/profile-view.tsx

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 45434478700

Coverage increased (+0.002%) to 56.468%

Details

  • Coverage increased (+0.002%) from the base build.
  • Patch coverage: 15 uncovered changes across 5 files (61 of 76 lines covered, 80.26%).
  • 2 coverage regressions across 2 files.

Uncovered Changes

File Changed Covered %
internal/store/postgres/user_repository.go 19 14 73.68%
internal/store/postgres/project_repository.go 15 11 73.33%
internal/store/postgres/group_repository.go 13 10 76.92%
internal/store/postgres/metadata_column.go 10 8 80.0%
internal/store/postgres/organization_repository.go 2 1 50.0%
Total (8 files) 76 61 80.26%

Coverage Regressions

2 previously-covered lines in 2 files lost coverage.

File Lines Losing Coverage Coverage
internal/store/postgres/organization_repository.go 1 79.07%
internal/store/postgres/user_repository.go 1 78.05%

Coverage Stats

Coverage Status
Relevant Lines: 42497
Covered Lines: 23997
Line Coverage: 56.47%
Coverage Strength: 22.11 hits per line

💛 - Coveralls

Comment thread internal/api/v1beta1connect/user.go Resolved
@rohilsurana
rohilsurana merged commit 4e33f29 into main Nov 25, 2026
10 of 11 checks passed
@rohilsurana
rohilsurana deleted the fix/keep-metadata-on-update branch November 25, 2026 05:11

This branch was successfully deployed

1 active deployment
Preview — b313e683 Deployed Nov 24, 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

3 participants