Skip to content

Fixes 34343: preserve data contract metadata when recording results - #34979

Merged
yan-3005 merged 5 commits into
open-metadata:mainfrom
lviola-qf:task/contract-result-upstream-20261008
Oct 21, 2026
Merged

yan-3005 merged 5 commits into
open-metadata:mainfrom
lviola-qf:task/contract-result-upstream-20261008

Conversation

@lviola-qf

@lviola-qf lviola-qf commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #34343

Bug: after a contract is edited, recording a validation result (the nightly Data Contract Validation app or PUT /v1/dataContracts/{id}/results) deletes the contract's custom properties (extension) and reviewers.

Root cause: both callers pass updateLatestResult() a contract loaded without extension/reviewers/owners. That method deep-copies the partial contract, sets latestResult, and runs the entity updater. The copy keeps the last editor's updatedBy/updatedAt, so the updater consolidates the write into that editor's version. Consolidation diffs the previous version (which has the fields) against the partial copy and records the missing fields as deleted. The loss is persisted into version history.

Fix: reload the stored contract with getPatchFields() before updating latestResult, so the original handed to the updater has every field the updater compares.

Note on main: #34304 has since landed an equivalent reload on main, with a hand-picked "owners,reviewers,extension" field list. This PR is merged with main and replaces that list with getPatchFields(). A relationship field added to the patch fields later is then covered automatically instead of being silently wiped on the next result write. The net diff against main is that one line plus the regression test.

Backport: 2.0 and 2.0.3–2.0.6 still use JsonUtils.deepCopy(dataContract, ...) without a reload, so the bug is live there (it was reported on 2.0.2).

Known limitation (out of scope): result writes still consolidate into the last user edit and are attributed to that user. The reload stops the data loss; changing the attribution would change version and change-event behaviour, so it should be tracked separately.

Developed and tested with assistance from OpenAI Codex (original change) and Claude Code (merge with main, getPatchFields() change, verification).

Type of change:

  • Bug fix

High-level design:

Not applicable — a two-file bug fix.

Tests:

Use cases covered

  • Custom properties, reviewers and description survive Running → Success results after a contract edit.
  • latestResult points to the recorded result with the expected status.
  • An older result does not replace the latest result.
  • Existing result creation and contract validation continue to work.

Backend integration tests

DataContractResourceIT.testContractResultsPreserveMetadata (new): adds a string custom property to the dataContract type, creates a contract with that property and a reviewer, edits it, records Running and Success results, and after each result asserts that the extension, reviewers and description are kept and that latestResult matches.

Run on the current head (06fd45fde5, merged with main), MySQL + Elasticsearch, parallel lane:

mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=parallel -Dit.test=DataContractResourceIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
Tests run: 184, Failures: 0, Errors: 0, Skipped: 0 -- in org.openmetadata.it.tests.DataContractResourceIT

The failsafe report from this run includes testContractResultsPreserveMetadata.

Manual testing performed (live server)

Standalone server on MySQL + Elasticsearch 9.3. Steps, through the REST API as admin:

  1. Add a string custom property to the dataContract type.
  2. Create a table and a contract on it with that property and reviewer admin.
  3. PATCH the contract description (version 0.1 → 0.2).
  4. PUT /v1/dataContracts/{id}/results with Running, then Success.
  5. GET the contract with fields=extension,reviewers after each result, and GET /versions.

Before the fix (updateLatestResult as on 2.0, no reload):

after edit             version=0.2 ext={'note_prefix1': 'Keep this note'} reviewers=['admin']
after result Running   version=0.2 ext=None reviewers=[]
after result Success   version=0.2 ext=None reviewers=[]
versions: [(0.2, None), (0.1, {'note_prefix1': 'Keep this note'})]

After the fix (this PR, getPatchFields()):

after edit             version=0.2 ext={'note_patch1': 'Keep this note'} reviewers=['admin']
after result Running   version=0.2 ext={'note_patch1': 'Keep this note'} reviewers=['admin'] latest=Running
after result Success   version=0.2 ext={'note_patch1': 'Keep this note'} reviewers=['admin'] latest=Success
versions: [(0.2, {'note_patch1': 'Keep this note'}), (0.1, {'note_patch1': 'Keep this note'})]

The search document for the contract (data_contract_search_index) still has its reviewer and custom property, with latestResult.status=Success.

Spotless passes on openmetadata-service and openmetadata-integration-tests.

Ingestion integration tests

Not applicable — no ingestion code changed.

Playwright (UI) tests

Not applicable — no UI code changed.

Earlier verification by the original author (pre-merge commit 817cd7be1f, before main's #34304 landed)

Local Java test run: PASSED

  • Commit: 545614e388b5 (base upstream/main) — uncommitted changes were present
  • Finished: 2026-10-08 20:45 UTC · 10.1 min
Step Scope Classes Tests Failed Skipped Min Result
unit openmetadata-service (7 classes) 7 211 0 0 1.5 passed
integration mysql-elasticsearch · parallel 13 1916 0 142 5.3 passed
integration mysql-elasticsearch · isolated 2 3 0 0 3.3 passed

Tests run locally

  • unit · openmetadata-service (7 classes): DataContractChildExtractionTest (15 passed), DataContractPipelineTokenRefreshTest (6 passed), DataContractValidateDQTest (4 passed), DataContractValidateWithoutThrowingTest (4 passed), MigrationUtilTest (158 passed), ODCSImportAnalyzerTest (13 passed), RuleEngineTest (11 passed)
  • integration · mysql-elasticsearch · parallel: BaseEntityIT$ListEntityHistoryByTimestampPaginationTest (12 passed), ConfigResourceIT (13 passed), DataAccessRequestValidationIT (85 passed, 11 skipped), DataContractPermissionIT (8 passed, 1 skipped), DataContractResourceIT (31 passed), DataProductDomainMigrationIT (309 passed, 28 skipped), DataProductResourceIT (303 passed, 24 skipped), DatabaseSmokeIT (1 passed), GlossaryTermResourceIT (251 passed, 25 skipped), SeedDataPresenceIT (1 passed), SoftDeleteRetentionIT (71 passed, 10 skipped), TableResourceIT (219 passed, 11 skipped), TestSuiteResourceIT (59 passed, 5 skipped), UserResourceIT (302 passed, 26 skipped)
  • integration · mysql-elasticsearch · isolated: DataContractValidationAppIT (2 passed), TestSuiteReindexIT (1 passed)

Per-class counts come from the test reports, which can credit a test to the wrong class when classes run concurrently, and keep only the last run of a nested class that several test classes inherit. The step totals above are Maven's own counts.

Why these tests
  • area data-contracts ← openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DataContractRepository.java
  • called from entity DataContract ← openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DataContractRepository.java
  • called from entity DataProduct ← openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DataContractRepository.java
  • called from entity TestSuite ← openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DataContractRepository.java
  • changed test ← openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/DataContractResourceIT.java
  • entity DataContract ← openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DataContractRepository.java
  • smoke ← code other than a test class changed
Commands
mvn -B package -pl openmetadata-service -am -Dspring-boot.repackage.skip=true -Dtest=DataContractChildExtractionTest,DataContractPipelineTokenRefreshTest,DataContractValidateDQTest,DataContractValidateWithoutThrowingTest,MigrationUtilTest,ODCSImportAnalyzerTest,RuleEngineTest -Dsurefire.failIfNoSpecifiedTests=false
mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=parallel -Dit.test=ConfigResourceIT,DataAccessRequestValidationIT,DataContractPermissionIT,DataContractResourceIT,DataProductDomainMigrationIT,DataProductResourceIT,DatabaseSmokeIT,GlossaryTermResourceIT,SeedDataPresenceIT,SoftDeleteRetentionIT,TableResourceIT,TestSuiteResourceIT,UserResourceIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=global-state -Dit.test=DataContractValidationAppIT,TestSuiteReindexIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false

UI screen recording / screenshots:

Not applicable — no UI changes.

Checklist:

  • I have read CONTRIBUTING.md.
  • My PR title is Fixes <issue-number>: <short explanation>.
  • My PR is linked to a GitHub issue via Fixes #34343.
  • The non-obvious reason for reloading the contract is documented in the code.
  • I added a regression for the exact failure and listed the tests above.
  • JSON Schema changes: not applicable.
  • UI changes: not applicable.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; the previous cleanup finding is fixed and no new actionable issues were found.

Summary

Uses getPatchFields() when reloading a contract before recording its latest result.

  • Recording a contract result keeps its saved metadata.

Reviews (2) · Last reviewed commit: "test: remove the data contract custom pr..." · Reviewed by Greptile

Reload the stored contract with its patch fields before updating latestResult. Partial validation objects must not erase custom properties or reviewer metadata during version consolidation.

Refs open-metadata#34343.
@lviola-qf
lviola-qf requested a review from a team as a code owner October 9, 2026 01:51
@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR checks passed

The linked issue has a description and all required Shipping project fields set. Thanks!

@github-actions

github-actions Bot commented Oct 9, 2026

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!

@harshach harshach added safe to test Add this label to run secure Github workflows on PRs To release Will cherry-pick this PR into the release branch labels Oct 9, 2026
@github-actions github-actions Bot removed the safe to test Add this label to run secure Github workflows on PRs label Oct 9, 2026
@github-actions

github-actions Bot commented Oct 9, 2026

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!

…upstream-20261008

# Conflicts:
#	openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/DataContractResourceIT.java
#	openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DataContractRepository.java
The updater diffs every patch field between original and updated. Loading the
original with a hand-picked "owners,reviewers,extension" list means any
relationship field added to the patch fields later is recorded as deleted on
every result write (open-metadata#34343). Use getPatchFields() so the reload always matches
what the updater compares.
@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!

@yan-3005 yan-3005 added the safe to test Add this label to run secure Github workflows on PRs label Oct 21, 2026
The property is registered on the shared dataContract type, which test
cleanup does not reap. Use CustomPropertyTestSupport and remove it in a
finally block so reused test servers do not accumulate properties.
@github-actions github-actions Bot removed the safe to test Add this label to run secure Github workflows on PRs label Oct 21, 2026
@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!

@yan-3005 yan-3005 added the safe to test Add this label to run secure Github workflows on PRs label Oct 21, 2026
@gitar-bot

gitar-bot Bot commented Oct 21, 2026

Copy link
Copy Markdown
Code Review ✅ Approved

🔴 High risk · Reloading patch fields before contract-result writes changes persisted version consolidation; fields omitted from that set could still be recorded as deletions.

Reloads the stored data contract with getPatchFields() before recording a validation result, so custom properties, reviewers and owners are no longer wiped on result writes. No issues found.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

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

@yan-3005
yan-3005 added this pull request to the merge queue Oct 21, 2026
Merged via the queue into open-metadata:main with commit 096ac83 Oct 21, 2026
122 of 128 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🤖 Backport to 2.0 is under way. It is built from openmetadata-collate, which holds the credentials needed to open a PR here, and it will comment again with the result — nothing is needed from you unless it reports otherwise.

@gh-bot-collate

Copy link
Copy Markdown

🤖 Not backported to 2.0. Claude looked at the conflict and declined to resolve it:

Backport aborted: PR #34979 does not apply to 2.0

Source PR

#34979 "Fixes 34343: preserve data contract metadata when recording results"
changes DataContractRepository.updateLatestResult on main from:

// Reload with the relationship fields the search doc is built from: callers pass contracts
// fetched without owners/reviewers, and the reindex after this update would blank them.
DataContract original =
    Entity.getEntity(Entity.DATA_CONTRACT, dataContract.getId(), "owners,reviewers,extension", Include.NON_DELETED);
DataContract updated = JsonUtils.deepCopy(original, DataContract.class);
...
getUpdater(original, updated, Operation.PATCH, null);

to:

DataContract original = get(null, dataContract.getId(), getPatchFields());
DataContract updated = JsonUtils.deepCopy(original, DataContract.class);
...
getUpdater(original, updated, Operation.PATCH, null);

i.e. it replaces a hand-picked reload field list (owners,reviewers,extension)
with getPatchFields(), so that any relationship field the updater diffs is
guaranteed to be loaded on original before the diff runs.

Why it doesn't apply to 2.0

The reload-and-diff pattern this PR fixes was introduced by PR #34304
("feat(search): add data_contract_search_index"), commit 010ec5c9c5, which
added the Entity.getEntity(..., "owners,reviewers,extension", ...) reload
and switched getUpdater(dataContract, updated, ...) to
getUpdater(original, updated, ...).

#34304 is not on 2.0. It has its own pending backport branch
(origin/backport/2.0/pr-34304, commit 010ec5c9c5) that has not been merged
into origin/2.0.

On current 2.0, updateLatestResult still has the pre-#34304 shape:

DataContract updated = JsonUtils.deepCopy(dataContract, DataContract.class);
updated.setLatestResult(...);
EntityRepository.EntityUpdater entityUpdater =
    getUpdater(dataContract, updated, EntityRepository.Operation.PATCH, null);
entityUpdater.update();

Here original and updated passed to getUpdater are both deep copies of
the same input object (whatever fields the caller happened to load), so for
any relationship field the caller didn't load, both sides are equally empty.
EntityUpdater's field updaters (e.g. updateOwners()) only touch a
relationship when recordListChange detects a difference between
original/updated — with both sides identically empty, no change is
recorded and no relationship is touched or deleted. The data-loss scenario
#34979 fixes (a relationship field that's loaded asymmetrically between
original and updated) cannot occur in this code shape, because it's
specific to the reload #34304 introduced.

Conclusion

This fix depends on a change (#34304) that is absent from 2.0 and whose own
backport is still pending. Applying #34979's diff as-is to 2.0's current code
would either fail to compile (no behavior to "re-fix") or silently graft in an
unrelated DB reload with no corresponding bug to justify it. Per the backport
rules, I'm not forcing a resolution here.

Recommendation: if/when origin/backport/2.0/pr-34304 lands on 2.0,
re-run the backport for #34979 — at that point the conflict will correspond
to a real bug on 2.0 and the main-branch resolution (reload via
getPatchFields()) can be applied directly, since getPatchFields() and the
get(UriInfo, UUID, Fields) overload it uses already exist on 2.0's
EntityRepository.

State left behind

The repository is left mid-cherry-pick (git cherry-pick -x 096ac83402 with
the single conflicting file still unmerged) exactly as it was handed off, per
instructions. No files were staged or modified beyond this note.

resolver run

sonika-shah added a commit that referenced this pull request Nov 4, 2026
…results (2.0) (#37009)

Backport of #34979. Recording a validation result patched a copy of the
contract loaded without owners/reviewers/extension, so after an edit the
updater recorded them as deleted. Reload the contract with its patch fields
before setting latestResult.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe to test Add this label to run secure Github workflows on PRs To release Will cherry-pick this PR into the release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Data contract custom properties (extension) deleted by the nightly Data Contract Validation run after the contract is edited

4 participants