Repository navigation
fix(data-quality): stop orphan test cases from breaking search indexing - #28159
Merged
Merged
Conversation
Hard-deleting a table could leave test cases behind whose relationship still pointed at the deleted executable test suite. The reindex loop then choked on "Error occurred when retrieving executable test suite for testCase ..." because that message doesn't match the stale-reference allow-list. Four layers of the fix: 1. TestCaseRepository.setFields / getTestSuites now tolerate hard-deleted suites and self-heal orphan relationship rows on the next read instead of throwing. 2. TableRepository.entitySpecificCleanup is a safety net for the cascade: it finds test cases by entityFQN (LIKE-escaped) and any leftover table->suite relationships, deleting them through the standard path so time-series, resolution status, and search docs are also cleaned up. 3. New OrphanTestCaseCleanup is wired into DataRetention to sweep test cases whose entityLink target is gone (the entity-relationship cleaner can't reason about string-based entityLink pointers). Skips soft-deleted test cases. 4. EntityRepository.cleanup now threads deletedBy through to a new entitySpecificCleanup(String, T) overload so cascade-deletes are credited to the actual operator instead of a hard-coded "admin"; the original signature still delegates so the nine existing overrides keep working unchanged. Tests: 6 LikeEscapeTest + 4 OrphanTestCaseCleanupTest unit tests, plus two new integration tests in TestCaseResourceIT covering the cascade and post-cascade listing. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1. Fix offset pagination bug: each successful delete shifts subsequent rows backward, so advancing the offset by the full batchSize skipped exactly that many rows. Now advance by batchSize - deletedInBatch so one run completes cleanup instead of needing repeated passes. 2. Narrow EntityLink.parse catch from Exception to IllegalArgumentException so only genuinely malformed links lead to deletion; any unexpected runtime error skips the row to avoid accidental data loss from a future parser bug. 3. Replace fully-qualified JsonUtils reference with a proper import. New unit test verifies the offset is advanced by survivors, not the batch size. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Contributor
🟡 Playwright Results — all passed (10 flaky)✅ 4247 passed · ❌ 0 failed · 🟡 10 flaky · ⏭️ 87 skipped
🟡 10 flaky test(s) (passed on retry)
How to debug locally# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip # view trace |
DataRetention.executeOrphanCleanup: replace `while(true)` with a 1000-iteration cap (10M rows at BATCH_SIZE=10k) so a delete query that always returns non-zero (e.g., rows blocked by FK constraints) can't spin forever and block the rest of the DataRetention job. Warns when the cap is hit so remaining work is visible; surviving rows are picked up on the next scheduled run. TestCaseResourceIT.test_recursiveHardDeleteCascadesPastResolutionStatusChildren: replace inline FQNs with imports for CreateTestCaseResolutionStatus and TestCaseResolutionStatusTypes, matching project convention. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
mohityadav766
approved these changes
May 26, 2026
|
Contributor
|
Failed to cherry-pick changes to the 1.13 branch. |
Contributor
|
Failed to cherry-pick changes to the 1.12.9 branch. |
This was referenced Aug 12, 2026
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Describe your changes:
When a table is hard-deleted, the cascade
table → executable test suite → test casesworks in the happy path but can leave test cases orphaned (legacy data, partial cascade failure, or test cases attached only to a logical suite). The next reindex throwsEntityNotFoundException("Error occurred when retrieving executable test suite for testCase ...")— and because that message doesn't match the stale-reference allow-list inReindexingUtil.isStaleReferenceError, the indexing app surfaces it as a real failure.This PR fixes the bug in four layers and adds a sweeper to clean up any orphans that already exist:
TestCaseRepository):setFieldsandgetTestSuitesno longer throw on missing test suites; they delete the danglingentity_relationshiprow inline so the next read self-heals.fetchAndSetTestSuitesDatadoes the same for the bulk path.TableRepository.entitySpecificCleanup): finds any test case whoseentityFQNmatches the deleted table FQN (LIKE-escaped via the newLikeEscapehelper) and any leftovertable → testSuiterelationship rows, and hard-deletes them throughEntity.deleteEntityso time-series, resolution status, and search docs are cleaned up too.OrphanTestCaseCleanup+DataRetention): scanstest_case, parses eachentityLink, looks up the target entity, and deletes the test case when the target is gone. Soft-deleted test cases are skipped.EntityRepository.cleanup): now threadsdeletedByto a newentitySpecificCleanup(String, T)overload so cascade-deletes are credited to the real operator instead of a hard-coded"admin". The original signature still delegates, so the 9 existing overrides keep working unchanged.Type of change:
High-level design:
TestCaseRepository.findExecutableTestSuiteForTestCaseis the new non-throwing variant used bysetFields. The throwinggetTestSuiteis kept becausegetOrCreateTestSuitestill uses the exception for control flow.TableRepository.deleteResidualTestCasesruns after the standarddeleteChildrencascade as a backstop. It uses a newCollectionDAO.TestCaseDAO.findIdsByEntityFQNSQL withESCAPE '\'so_and%in table FQNs don't over-match.OrphanTestCaseCleanupis the complement toEntityRelationshipCleanup: that utility cleans broken rows inentity_relationship, but it can't reason about the string-basedentityLinkpointer. The new sweeper runs inDataRetentionafter the relationship pass so a recently-restored suite doesn't get its test cases wiped.entitySpecificCleanup(String deletedBy, T)is additive — the default implementation delegates to the oldentitySpecificCleanup(T), soAppRepository,PipelineRepository,QueryRepository,TestCaseRepository, etc. don't need changes.TableRepositoryopts into the new overload.Tests:
Use cases covered
EntityNotFoundExceptionleaking throughsetFields).DataRetentionsweeper deletes test cases whoseentityLinktarget is gone, but leaves soft-deleted test cases alone.my_tablefrom matchingmyXtablewhen searching by FQN prefix.Unit tests
openmetadata-service/src/test/java/org/openmetadata/service/util/OrphanTestCaseCleanupTest.java(4 tests),openmetadata-service/src/test/java/org/openmetadata/service/util/LikeEscapeTest.java(6 tests).Backend integration tests
openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/TestCaseResourceIT.java—test_deleteTableCascadesTestSuiteAndTestCasesandtest_listTestCasesReturnsTestSuiteFieldAfterCascade.Ingestion integration tests
Playwright (UI) tests
Manual testing performed
UI screen recording / screenshots:
Not applicable.
Checklist:
🤖 Generated with Claude Code
Summary by Gitar
MAX_ORPHAN_CLEANUP_ITERATIONScap toexecuteOrphanCleanupto prevent infinite loops inDataRetentionjobs.TestCaseResourceITto improve code readability.LikeEscapeandCollectionDAOfromESCAPE '\'toESCAPE '!'to resolve MySQL string-literal conflicts and JDBI parsing issues.LikeEscapeTestto reflect the new bang-based escaping convention and ensure backslash literals are preserved.This will update automatically on new commits.