You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: keep stored metadata when a project, group or user update does not set it - #2058
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.
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.
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 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.
Regression tests check that omitted metadata is preserved, supplied metadata replaces it, and empty metadata clears it for groups, projects, and users.
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: 1 · 1
Failed checks: 1 inconclusive
Check name
Status
Explanation
Resolution
Out of Scope Changes check
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 checks: 1 passed
Check name
Status
Explanation
Linked Issues check
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.
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2030.
Problem
Updating a project, group or user replaced the whole
metadatacolumn with what the request sent.If a client left
metadataout, the stored keys were wiped.#2019 fixed this for organizations. This PR does the same for project, group and user.
UpdateCurrentUseralready skipped metadata when it was not set.But the repository then wrote JSON
nullover the stored value, so it lost data too.What changed
UpdateProject,UpdateGroup,UpdateUser,UpdateCurrentUser) read metadata only when the request sets it.metadatacolumn alone when metadata is nil.UpdateByID,UpdateByNameUpdateByIDUpdateByID,UpdateByEmail,UpdateByNameBehavior
{}: the stored metadata is cleared.Behavior change for API clients
metadataout to clear it must now send{}.{}clears metadata, the same as the other update paths.Tests
{}.make lintis clean. Unit, repository and the full e2e regression suite pass.