Skip to content

fix(organization): preserve existing metadata when updating organization description - #6487

Open
pedrofrxncx wants to merge 1 commit into
mainfrom
fix/organization-update-metadata-preservation-w4
Open

fix(organization): preserve existing metadata when updating organization description#6487
pedrofrxncx wants to merge 1 commit into
mainfrom
fix/organization-update-metadata-preservation-w4

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Source

Inspecting the organization tools cleanup area, found that ORGANIZATION_UPDATE overwrites the entire organization metadata object instead of merging the new description field into it. This causes other metadata fields (e.g., archived, archivedAt) to be silently lost when updating just the description.

Impact

When calling ORGANIZATION_UPDATE with a new description on an organization that already has metadata, all existing metadata fields except description are dropped from the metadata object. This can cause data loss of any fields stored in organization metadata.

Solution

Fetch the existing organization metadata before updating, then merge the new description field into it instead of replacing the entire object. This ensures all existing metadata fields are preserved.

Regression Test

Added test merges description into existing metadata instead of replacing it that verifies:

  • When an organization has existing metadata ({ archived: true, archivedAt: "..." })
  • And ORGANIZATION_UPDATE is called with a new description
  • The resulting update preserves the archived and archivedAt fields
  • While adding the new description field

Verification

  • bun test apps/api/src/tools/organization/update.test.ts — all 3 tests pass (2 existing + 1 regression)
  • bunx tsc --noEmit in apps/api — no type errors
  • bun run fmt — no formatting changes needed
  • Unit test confirms behavior-preserving: existing tests still pass, new test enforces metadata merging

Line Delta

-3 / +58 in two files (update.ts: core fix, update.test.ts: regression test + test setup)


Summary by cubic

Preserves existing organization metadata when updating the description to prevent data loss. Previously, ORGANIZATION_UPDATE replaced metadata with { description }, dropping fields like archived and archivedAt; now it merges description into existing metadata.

  • Fetches current organization metadata via ctx.boundAuth.organization.get and merges it with the new description (null/empty string still clears description).
  • Adds a regression test that verifies archived and archivedAt are preserved.
  • Introduces one extra read per update call.
  • No API changes and no migration required.

Written for commit 8f81be8. Summary will update on new commits.

Review in cubic

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.

1 participant