Skip to content

Fixes 20966: clear sourceHash on PATCH so the bulk fast-path resyncs edited entities - #32246

Closed
zak-nuccio wants to merge 1 commit into
open-metadata:mainfrom
zak-nuccio:fix/sourcehash-clear-on-patch
Closed

zak-nuccio wants to merge 1 commit into
open-metadata:mainfrom
zak-nuccio:fix/sourcehash-clear-on-patch

Conversation

@zak-nuccio

@zak-nuccio zak-nuccio commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Why

Closes #20966.

The bulk PUT /api/v1/tables/bulk fast-path (introduced in #28155) skips any entity whose
connector-supplied sourceHash matches the stored value, before any field hydration or diffing.
The stored sourceHash is never cleared when an entity is edited out-of-band via PATCH, so a
manual edit (e.g. a tag removed in the UI) is silently lost on the next ingestion run: the identical
sourceHash compares equal and the entity is skipped.

Concretely:

  1. Ingestion writes a table with tags -> stored sourceHash = H(tags).
  2. Tags are cleared via PATCH (UI/automation/direct API) -> stored sourceHash stays H(tags).
  3. Next ingestion re-derives the same tags from source -> same hash H(tags).
  4. The fast-path sees H(tags) == H(tags) -> skip -> tags never restored.

Before 2.0.0 the bulk path processed every entity, so tags always re-synced from source. This is a
regression from the sourceHash feature.

Fix

Clear sourceHash on every PATCH. All PATCH endpoints funnel through
EntityRepository.patchCommonWithOptimisticLocking, so this is a single point of change. The next
bulk run then sees a null stored hash, isSourceHashUnchanged returns false, and the full diff path
re-applies the source content. The next ingestion re-stamps the hash, so the fix costs at most one
extra reprocess after a manual edit rather than losing the edit permanently.

  • EntityInterface: add a default void setSourceHash(String) no-op (mirrors the existing
    default String getSourceHash()); generated entity POJOs that declare sourceHash already
    override it with a real setter.
  • EntityRepository.patchCommonWithOptimisticLocking: set updated.setSourceHash(null) before
    persisting, after restorePatchSecrets so no hook can restore it.

Trade-off

Clearing on every PATCH also affects ingestion-driven PATCHes (e.g. lineage or bulk description
patches), disabling the fast-path for those entities on the next bulk run. That is a performance
cost, not a correctness one, and only until the next successful ingestion re-stamps the hash. If
that matters for high-volume PATCH connectors, a follow-up could restrict the clear to patches not
authored by the ingestion bot.

Test

Adds test_manualPatchClearsSourceHash_soSameHashReappliesTags to BulkSourceHashFastPathIT:
creates a table with a tag and a sourceHash, PATCH-clears the tag (asserting the stored
sourceHash becomes null), then re-ingests the identical batch and asserts the tag is re-applied -
proving the fast-path does not skip after a manual PATCH edit.

Verified with mvn spotless:apply on the touched modules and mvn compile on
openmetadata-spec (clean). openmetadata-service compiles the changed files clean; the full module
build is blocked in this environment by a pre-existing relocated-ES-class error in
ElasticSearchClient/SearchUtils unrelated to this change.

Greptile Summary

The PR invalidates an entity’s stored source hash after a meaningful PATCH so the next bulk ingestion performs a full reconciliation instead of incorrectly taking the unchanged-hash fast path.

  • Adds a common optional source-hash setter to the entity interface.
  • Clears sourceHash during the shared PATCH lifecycle before persistence.
  • Adds an integration test covering tag removal followed by same-hash bulk re-ingestion.

Confidence Score: 4/5

The PR appears safe to merge; the only identified issue is non-blocking redundant commentary in the regression test.

The shared PATCH flow clears and persists sourceHash for meaningful edits, allowing the next bulk ingestion to perform reconciliation, and no blocking correctness or security failure remains.

Files Needing Attention: openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/BulkSourceHashFastPathIT.java

Important Files Changed

Filename Overview
openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java Clears sourceHash in the common PATCH path; changed PATCHes persist the invalidation without creating a sourceHash-only version event.
openmetadata-spec/src/main/java/org/openmetadata/schema/EntityInterface.java Adds an optional no-op setter so generic repository code can invalidate hashes on generated entities that expose the property.
openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/BulkSourceHashFastPathIT.java Covers PATCH invalidation and same-hash tag restoration, with minor redundant comments in the new test helpers.

Sequence Diagram

sequenceDiagram
  participant Client
  participant Patch as PATCH lifecycle
  participant Store
  participant Bulk as Bulk ingestion
  Client->>Patch: Edit entity metadata
  Patch->>Patch: Clear sourceHash
  Patch->>Store: Persist edited entity
  Bulk->>Store: Read stored entity
  Store-->>Bulk: sourceHash is null
  Bulk->>Bulk: Bypass unchanged-hash fast path
  Bulk->>Store: Reconcile source metadata and stamp hash
Loading

Reviews (1): Last reviewed commit: "Fixes 20966: clear sourceHash on PATCH s..." | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

Context used (3)

…edited entities

The bulk PUT fast-path skips any entity whose connector-supplied sourceHash matches the stored
value. The stored sourceHash was never cleared when an entity was edited out-of-band via PATCH,
so a manual edit (for example a tag removed in the UI) was not re-applied on the next ingestion
run: the identical sourceHash compared equal and the entity was skipped before any diff.

Clear sourceHash on every PATCH so the next bulk run sees a null stored hash, takes the full diff
path and re-applies the source content. The next ingestion re-stamps the hash, so the fix forces
at most one extra reprocess after a manual edit rather than discarding the edit permanently.

Add a regression IT that PATCH-clears a tag and re-ingests with a matching sourceHash, asserting
the tag is re-applied.
@zak-nuccio
zak-nuccio requested a review from a team as a code owner August 28, 2026 13:54
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@github-actions

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@@ -187,6 +230,61 @@ private String tableFqn(String schemaFqn, String tableName) {
return schemaFqn + "." + tableName;
}

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.

P2 Redundant helper comments

The new comments above createClassificationAndTag, patchTableTagsToEmpty, and the manual patch call merely restate the self-explanatory operations, adding maintenance noise without documenting non-obvious rationale.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@gitar-bot

gitar-bot Bot commented Aug 28, 2026

Copy link
Copy Markdown
Code Review ✅ Approved

Fixes the regression where manual edits via PATCH are silently lost on the next ingestion run by clearing sourceHash when entities are patched. The fix adds a setSourceHash default method to EntityInterface and clears the hash in EntityRepository.patchCommonWithOptimisticLocking, ensuring the bulk fast-path reprocesses edited entities. Test coverage included. No issues found.

Options

Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@harshach

Copy link
Copy Markdown
Collaborator

The goal of sourceHash is to preserve whats in the Source which is snowflake, databricks etc.. if nothing chnaged in source there is no reason to write it again. If we start incorporating the patch , any edits in the UI by the user now impacts the sourceHash, then everytime we run ingestion we write all the objects as the source hash is changed on the OM side.

Can you give us an example what PATCH are you running, is the PATCH coming from the ingestion or externally

@zak-nuccio

Copy link
Copy Markdown
Contributor Author

@harshach For context, this was to try and get around the issue of wanting to make manual changes to a table in OpenMetadata, but hitting the issue that sourceHash would make the ingestion think nothing was changed, and thus a later bulk load wouldn't overwrite the change (which we wanted to use for ingestion testing).

After some digging, we realised that sourceHash can actually just be edited via a PATCH call too, so instead we'll just be using a call to remove the hash so that later bulk ingestions see that the table should be reingested.

Closing

@zak-nuccio zak-nuccio closed this Sep 1, 2026
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.

Weird behaviour around Ingesting tags due to sourceHash

2 participants