Skip to content

fix(organization): keep stored metadata when an update does not set it - #2019

Merged
rohilsurana merged 5 commits into
mainfrom
fix/org-update-keep-metadata-main
Oct 27, 2026
Merged

rohilsurana merged 5 commits into
mainfrom
fix/org-update-keep-metadata-main

Conversation

@rohilsurana

@rohilsurana rohilsurana commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Problem

Updating an organization replaced the whole metadata column. The settings forms in the client and admin UI do not send the full metadata. Saving them removed keys such as poc from the org.

Change

  • If metadata is not set in the update request, the metadata column is left as it is and schema validation is skipped.
  • If metadata is set, it replaces the stored value. This includes an empty {}, so metadata can still be cleared on purpose.

UpdateOrganization is the only place that updates an org. The change is in the handler and in UpdateByID and UpdateByName in the org repository.

Notes

  • The audit record for an update stores the metadata saved on the org. When the update skips metadata, the record shows the stored metadata. When it clears metadata, the record shows none.
  • Title and avatar are still replaced when omitted. That needs a separate change.
  • Orgs that already lost their metadata are not restored by this PR.

Tests

  • Handler: metadata not set, by id and by name, metadata set to {}.
  • Repository: nil keeps stored metadata, a value replaces it, {} clears it, for both update by id and by name. Each case also checks the metadata in the update audit record.

@vercel

vercel Bot commented Oct 22, 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 Oct 26, 2026 11:31am UTC

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between d819577 and cd65d38.

Files selected for processing: 2
  • internal/store/postgres/organization_repository.go
  • internal/store/postgres/organization_repository_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.

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Updating an organization without specifying metadata now preserves its existing metadata, rather than replacing it.
    • Supplying an empty metadata object still clears the organization’s metadata.
    • Editing an organization’s size, type, or country now retains its other metadata fields.
    • Supplied metadata continues to be validated; invalid metadata is rejected. Updates that omit metadata skip metadata validation.

Organization updates now distinguish omitted metadata from explicitly empty metadata. The API, PostgreSQL repository, admin edit payload, and tests reflect this distinction.

Changes: Organization Metadata Updates

Layer / File(s) Summary
Handle optional metadata in update requests
internal/api/v1beta1connect/organization.go, internal/api/v1beta1connect/organization_test.go
UpdateOrganization leaves omitted metadata nil and validates supplied metadata. Tests cover ID and slug requests, including explicitly empty metadata.
Apply metadata update semantics in PostgreSQL
internal/store/postgres/organization_repository.go, internal/store/postgres/organization_repository_test.go
Both update methods use a shared helper that omits the metadata column when metadata is nil. Updated models supply metadata for audit records. Tests check that nil preserves stored metadata, populated metadata replaces it, and an empty map clears it.
Preserve metadata in admin updates and verify end-to-end behavior
web/sdk/admin/views/organizations/details/edit/organization.tsx, test/e2e/regression/organization_metadata_test.go
The admin edit payload includes existing metadata before applying edited fields. An end-to-end test checks omitted, populated, and empty metadata updates.

Priority: Normal

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

Change: Bug fix

Suggested reviewers: amangit07, mabdh

Merge Risk: Minimal · up to cd65d

No actionable merge-blocking risk remains.

Pre-merge checks: Passed 2
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • 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

Comment @coderabbitai help to get the list of available commands.

@coveralls

coveralls commented Oct 22, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 40315589019

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage increased (+0.1%) to 55.736%

Details

  • Coverage increased (+0.1%) from the base build.
  • Patch coverage: 8 uncovered changes across 1 file (37 of 45 lines covered, 82.22%).
  • 293 coverage regressions across 7 files.

Uncovered Changes

File Changed Covered %
internal/store/postgres/organization_repository.go 39 31 79.49%
Total (2 files) 45 37 82.22%

Coverage Regressions

293 previously-covered lines in 7 files lost coverage.

File Lines Losing Coverage Coverage
pkg/server/connect_interceptors/authorization.go 98 0.0%
internal/store/postgres/policy_repository.go 89 75.61%
core/deleter/service.go 69 83.95%
internal/store/postgres/resource_repository.go 30 74.77%
core/deleter/deleter.go 3 78.57%
internal/api/v1beta1connect/deleter.go 3 95.89%
core/resource/service.go 1 82.29%

Coverage Stats

Coverage Status
Relevant Lines: 41937
Covered Lines: 23374
Line Coverage: 55.74%
Coverage Strength: 19.5 hits per line

💛 - Coveralls

@rohanchkrabrty rohanchkrabrty left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Before this change, the audit record always had the same metadata as the org row. Now, when an update does not send metadata, the org keeps its metadata but the audit record has none. Is this intended?

Comment thread internal/store/postgres/organization_repository.go
@rohilsurana
rohilsurana merged commit 2a74b8c into main Oct 27, 2026
8 checks passed
@rohilsurana
rohilsurana deleted the fix/org-update-keep-metadata-main branch October 27, 2026 06:31

This branch was successfully deployed

1 active deployment
Preview — cd65d38a Deployed Oct 26, 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.

4 participants