Skip to content

Fix METADATA_ALREADY_EXISTS error in CrossKalturaDistributionEngine metadata sync - #2

Open
devin-ai-integration[bot] wants to merge 2 commits into
Scorpius-19.6.0from
devin/1777272647-fix-metadata-already-exists
Open

Fix METADATA_ALREADY_EXISTS error in CrossKalturaDistributionEngine metadata sync#2
devin-ai-integration[bot] wants to merge 2 commits into
Scorpius-19.6.0from
devin/1777272647-fix-metadata-already-exists

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Apr 27, 2026

Copy link
Copy Markdown

Summary

Fixes a bug in CrossKalturaDistributionEngine::sync() where syncing metadata objects to a target entry fails with METADATA_ALREADY_EXISTS if someone manually added metadata to the target entry outside the distribution flow.

Problem: When metadata is not in the distributedMap (i.e., not previously distributed), the code always tries to add new metadata. If matching metadata (same metadataProfileId) was manually created on the target entry, the add call fails because metadata is unique per (objectId, metadataProfileId, objectType).

Fix: Before adding each metadata object, do a targeted metadata->listAction() filtered by objectIdEqual, metadataObjectTypeEqual, and metadataProfileIdEqual to check if metadata for that specific profile already exists on the target. If it does, inject the existing target metadata ID into the distributed map so syncTargetEntryObjects treats it as an update instead of an add.

This per-profile approach only makes the list call for metadata objects not already in the distributed map, and filters by the exact profile being added — avoiding unnecessary data transfer.

Review & Testing Checklist for Human

  • Test the scenario: manually add metadata to a target entry, then trigger a distribution update — confirm it updates instead of failing with METADATA_ALREADY_EXISTS
  • Test the normal flow (no manually added metadata) still works — the list call finds nothing and the add proceeds as before
  • Verify that if the list call itself fails (e.g., permissions), the warning is logged and the original add flow proceeds (graceful degradation)

Notes

  • The distributedMap is rebuilt from scratch after sync via getDistributedMap(), so injecting synthetic entries before the sync has no lasting side effects
  • When DISTRIBUTED_INFO_SOURCE_UPDATED_AT is not set in the injected entry, the update path in syncTargetEntryObjects correctly falls through to perform the update (the null check ensures this)

Link to Devin session: https://app.devin.ai/sessions/85d0938a18374be38b10c6f88edca4e5
Requested by: @bw-kaltura

…raDistributionEngine

Before adding metadata to the target entry, list existing metadata to
detect manually created metadata objects. If metadata for the same
profile already exists on the target, update it instead of attempting
to add, which would fail with METADATA_ALREADY_EXISTS.

Co-Authored-By: bryna.weissman@kaltura.com <bryna.weissman@kaltura.com>
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

…upfront

Only list metadata for the specific metadataProfileId being added,
rather than fetching all metadata on the target entry. This is more
targeted and avoids unnecessary data transfer when most metadata
objects are already tracked in the distributed map.

Co-Authored-By: bryna.weissman@kaltura.com <bryna.weissman@kaltura.com>
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