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.
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.
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 updates omit the metadata column for nil values and write non-nil values, including empty maps. Tests cover preservation, replacement, and clearing.
Regression tests check that omitted metadata is preserved, supplied metadata replaces it, and empty metadata clears it for groups, projects, and users.
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: 2
Check name
Status
Explanation
Linked Issues check
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
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.
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.
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.