Skip to content

fix(drive): add deleteStale endpoint and set File column FQNs on write - #31375

Merged
IceS2 merged 11 commits into
mainfrom
fix/sftp-drive-blockers
Aug 13, 2026
Merged

IceS2 merged 11 commits into
mainfrom
fix/sftp-drive-blockers

Conversation

@Khairajani

@Khairajani Khairajani commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #31381

Two defects found while testing the SFTP connector for the 2.0 release. Both sit in the Drive entity
layer, so they affect GoogleDrive and SharePoint identically — not just SFTP.

1. deleteStale was never exposed on the Drive resources

Every ingestion run ended with three HTTP 405 Method Not Allowed:

PUT /v1/drives/directories/deleteStale
PUT /v1/drives/files/deleteStale
PUT /v1/drives/spreadsheets/deleteStale

PUT /v1/tables/deleteStale returns 400 (route exists, body rejected) — 405 vs 400 is the tell. The
endpoint is declared on TableResource, TopicResource, ContainerResource and five others, but was
missing from all four Drive resources.

Impact: markDeletedDirectories / markDeletedFiles were silent no-ops — a file deleted at the
source stayed in the catalogue forever. It also made every run report Failed even when extraction
succeeded, so a real failure was indistinguishable from the permanent one.

Fix: declare the endpoint on Directory, File, Spreadsheet and Worksheet. No new logic —
EntityResource.deleteStaleEntities is fully generic, and resolveScopeEntityType already maps
directory/file to driveService via ENTITY_SERVICE_TYPE_MAP.

2. FileRepository never set column FQNs on the write path

The first ingestion of a service was clean; every run after it failed on each file with columns:

Cannot invoke "String.equals(Object)" because the return value of
"org.openmetadata.schema.type.Column.getFullyQualifiedName()" is null

Observed 0 errors on run 1, then 17 and 18 on runs 2 and 3, reproduced on three separate services and
through the CLI.

Impact: metadata was frozen at whatever the first run captured — a column added at the source
could never reach OpenMetadata.

Cause: setColumnFQN was called in setFields (the read path) but not in
setFullyQualifiedName (the write path), so columns were persisted with a null FQN and the update
comparison NPE'd. WorksheetRepository already does this correctly inside setFullyQualifiedName;
FileRepository now matches, guarded with a null check because non-tabular files (images, PDFs,
parquet) have no columns and ColumnUtil.setColumnFQN does not accept null.

Testing

Found against a live SFTP server on release-2-0, driving real ingestion through both a hybrid runner
and the CLI. mvn compile and spotless:apply clean.

Full test notes: 17 bugs found across phases 0–4; these are the two blockers that need server-side
changes. The connector's own remaining issues are being fixed separately.

Two defects that make Drive connectors (SFTP, GoogleDrive, SharePoint) unusable
in normal operation.

1. deleteStale was never exposed on the Drive resources, so every ingestion run
   ended with three HTTP 405s and marked itself Failed even when extraction had
   succeeded. markDeletedDirectories / markDeletedFiles were silently no-ops and
   entities removed at the source stayed in the catalogue forever. The endpoint
   is declared on Table, Topic, Container and five other resources; Directory,
   File, Spreadsheet and Worksheet were missing it. The implementation is fully
   generic in EntityResource.deleteStaleEntities and the service-scope resolution
   already maps directory/file to driveService, so this only needed the four
   endpoint declarations.

2. FileRepository set column FQNs when reading an entity back (setFields) but
   never on the write path. The update path compares columns by FQN, so a second
   ingestion of any file with columns failed with

       Cannot invoke "String.equals(Object)" because the return value of
       "Column.getFullyQualifiedName()" is null

   leaving metadata frozen at whatever the first run captured. WorksheetRepository
   already does this inside setFullyQualifiedName; FileRepository now matches,
   guarded for the non-tabular files that have no columns.
@Khairajani
Khairajani requested a review from a team as a code owner August 12, 2026 06:21
@github-actions

github-actions Bot commented Aug 12, 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

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!

@github-actions

github-actions Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

✅ Playwright Results — workflow succeeded

Validated commit 5d0b3c602542ad884fad651e13566344572042fb in Playwright run 31672502111, attempt 1.

✅ 821 passed · ❌ 0 failed · 🟡 1 flaky · ⏭️ 0 skipped · 🧰 0 lifecycle flaky

Performance

Blocking targets: ✅ met · Optimization targets: 🟡 in progress

Shard-job maxima below are not the full workflow wall time; the linked run includes build, fixture, planning, and reporting.

🕒 Full workflow signal wall (to summary) 50m 59s

⏱️ Max setup 3m 11s · max shard execution 19m 1s · max shard-job elapsed before upload 22m 23s · reporting 7s

🌐 210.80 requests/attempt · 2.48 app boots/UI scenario · 26.29% common-shard skew

Optimization targets still in progress:

  • Common shard skew was 26.29% (convergence target: at most 15%).
  • Browser traffic was 210.8 requests per attempt (convergence target: fewer than 200).
  • Application boot ratio was 2.48 per UI scenario (2120 boots / 854 scenarios; convergence target: at most 1).
Shard Passed Failed Flaky Skipped Lifecycle failed Lifecycle flaky
✅ Shard chromium-01 163 0 0 0 0 0
🟡 Shard chromium-02 150 0 1 0 0 0
✅ Shard chromium-03 142 0 0 0 0 0
✅ Shard chromium-04 152 0 0 0 0 0
✅ Shard data-asset-rules-01 61 0 0 0 0 0
✅ Shard domain-isolation-01 14 0 0 0 0 0
✅ Shard global-state-01 34 0 0 0 0 0
✅ Shard ingestion-01 37 0 0 0 0 0
✅ Shard ingestion-02 27 0 0 0 0 0
✅ Shard reindex-01 2 0 0 0 0 0
✅ Shard search-01 10 0 0 0 0 0
✅ Shard search-rbac-01 29 0 0 0 0 0
🟡 1 flaky test(s) (passed on retry)
  • Pages/Entity.spec.ts › Domain Propagation (shard chromium-02, 1 retry)

📦 Download artifacts

How to debug locally
# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip    # view trace

@Khairajani Khairajani added the safe to test Add this label to run secure Github workflows on PRs label Aug 12, 2026
@Khairajani Khairajani self-assigned this Aug 12, 2026
…olumns

Follow the repo Java conventions: no fully-qualified class names in code (the
new deleteStale blocks referenced org.openmetadata.schema.type.api.BulkOperationResult
inline; TableResource imports it), and use CommonUtil.listOrEmpty for the columns
guard instead of a null check, matching how ContainerRepository and TableRepository
handle optional column lists.
Enabling deleteStale exposed a latent bug in the SFTP source: the FQNs it
registers as "seen" during a run did not match the FQNs the create requests
actually store, so stale-entity deletion removed entities that had just been
ingested correctly.

Two mismatches:

- Files used the base register_record_file, which builds the FQN from a single
  context directory. For a file nested two levels deep that yields
  service.nested."f.csv" instead of service.data.nested."f.csv", and for a
  root-level file there is no context directory at all. Override it and pass the
  same path components the create request uses, with a direct _build for
  root-level files since fqn.build rejects an empty directory path.

- register_record_directory already built the correct path-based FQN on its main
  branch; its docstring now records why the FQN has to match, so the fallback is
  not "simplified" back to the bare name later.

These tests were passing before only because deleteStale returned 405 and no
deletion ever happened - with deletion working, six SFTP integration tests
covering nested directories and root-level files correctly began to fail.
@Khairajani
Khairajani requested a review from a team as a code owner August 12, 2026 11:29
…mpty

SftpDirectoryInfo.path is optional. yield_directory and register_record_directory
both fall back to `[directory_info.name]` when it is empty, but the file
registration path did not - so a nested file whose directory carried no path
components would register the root-level FQN and be deleted as stale straight
after being ingested. Use the same fallback everywhere.
…new line

TopologyContext attributes are populated dynamically, so basedpyright cannot see
drive_service. The ten pre-existing accesses in this file are carried in the
static-check baseline; a newly added line is not, and the baseline runs in
discard mode, which fails on any new error. Suppress it inline the same way
googledrive/connection.py does.
IceS2 and others added 2 commits August 12, 2026 23:09
SourceAPIClient.delete wraps REST.delete, which gained a `json` parameter
ahead of `headers` when deleteStale moved to the DELETE verb. The wrapper
kept the old four-positional signature, so the override no longer matched
the base. Mirror the new signature and pass `json` through.

GoogleDriveSource.register_record_file reads context.drive_service, which
TopologyContext populates dynamically. The pre-existing accesses are carried
in the static-check baseline; a new line is not, and the baseline runs in
discard mode. Suppress it inline the same way the SFTP source does.
@sonarqubecloud

Copy link
Copy Markdown

@IceS2
IceS2 added this pull request to the merge queue Aug 13, 2026
Merged via the queue into main with commit 29cfb16 Aug 13, 2026
134 checks passed
@IceS2
IceS2 deleted the fix/sftp-drive-blockers branch August 13, 2026 12:49
@gitar-bot

gitar-bot Bot commented Aug 13, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 3 resolved / 3 findings

Adds the missing deleteStale endpoint and fixes column FQN assignment on the write path for drive entities. Addressed the File FQN directory-name fallback, deleteStale request body on DELETE, and null stored FQN rename map key findings.

✅ 3 resolved
✅ Edge Case: File FQN skips the directory-name fallback used elsewhere

📄 ingestion/src/metadata/ingestion/source/drive/sftp/metadata.py:585-589 📄 ingestion/src/metadata/ingestion/source/drive/sftp/metadata.py:629 📄 ingestion/src/metadata/ingestion/source/drive/sftp/metadata.py:410-418 📄 ingestion/src/metadata/ingestion/source/drive/sftp/metadata.py:442-456
In yield_file, directory_path_components is set to self._directories_cache[directory_path].path with no fallback, whereas yield_directory and register_record_directory both use directory_info.path or [directory_info.name] to build the directory FQN. If a cached directory ever has an empty/None path, the file's create request still carries directory=directory_reference (so the server stores the FQN as <dir_fqn>.<file>), but register_record_file falls into the root-level branch and records service.file. That mismatch is exactly the stale-deletion hazard this PR guards against, and would delete a just-ingested file. Apply the same fallback: pass self._directories_cache[directory_path].path or [self._directories_cache[directory_path].name] so the recorded FQN matches the directory FQN.

✅ Edge Case: deleteStale relies on a request body carried on DELETE

📄 ingestion/src/metadata/ingestion/ometa/client.py:513 📄 ingestion/src/metadata/ingestion/ometa/client.py:525 📄 openmetadata-integration-tests/src/test/java/org/openmetadata/it/util/BulkApi.java:70-73
Switching deleteStale from PUT to DELETE moves the seen-FQN set into a DELETE request body, whose semantics are undefined by RFC 7231; some proxies/load balancers/gateways strip bodies from DELETE requests. If the body is dropped the server receives an empty seen-set — safe only because the server treats an empty seen-set as a no-op (verified by the IT test emptySeenFqns_withPopulatedScope_deletesNothing). Worth confirming this guard is robust in production topologies, otherwise a stripped body could silently prevent stale deletion; keeping the endpoint documented as body-carrying is advisable.

✅ Edge Case: Null stored FQN can insert a null key into rename map

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java:10637-10640
With Objects.equals, when stored.getFullyQualifiedName() is null the condition is true and originalUpdatedColumnFqns.putIfAbsent(null, updatedFqn) inserts a null key. This map is passed to handleColumnLineageUpdates, which for TableRepository forwards it to lineageRepository.updateColumnLineage and searchClient.updateColumnsInUpstreamLineage as a rename mapping. It is harmless for Drive files (base no-op) and Table columns never have null FQNs today, so the risk is theoretical, but consider skipping the map insert when stored.getFullyQualifiedName() == null to avoid a null-keyed rename entry ever reaching lineage/search code.

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

IceS2 added a commit that referenced this pull request Aug 13, 2026
#31375)

* fix(drive): add deleteStale endpoint and set File column FQNs on write

Two defects that make Drive connectors (SFTP, GoogleDrive, SharePoint) unusable
in normal operation.

1. deleteStale was never exposed on the Drive resources, so every ingestion run
   ended with three HTTP 405s and marked itself Failed even when extraction had
   succeeded. markDeletedDirectories / markDeletedFiles were silently no-ops and
   entities removed at the source stayed in the catalogue forever. The endpoint
   is declared on Table, Topic, Container and five other resources; Directory,
   File, Spreadsheet and Worksheet were missing it. The implementation is fully
   generic in EntityResource.deleteStaleEntities and the service-scope resolution
   already maps directory/file to driveService, so this only needed the four
   endpoint declarations.

2. FileRepository set column FQNs when reading an entity back (setFields) but
   never on the write path. The update path compares columns by FQN, so a second
   ingestion of any file with columns failed with

       Cannot invoke "String.equals(Object)" because the return value of
       "Column.getFullyQualifiedName()" is null

   leaving metadata frozen at whatever the first run captured. WorksheetRepository
   already does this inside setFullyQualifiedName; FileRepository now matches,
   guarded for the non-tabular files that have no columns.

* refactor(drive): import BulkOperationResult and use listOrEmpty for columns

Follow the repo Java conventions: no fully-qualified class names in code (the
new deleteStale blocks referenced org.openmetadata.schema.type.api.BulkOperationResult
inline; TableResource imports it), and use CommonUtil.listOrEmpty for the columns
guard instead of a null check, matching how ContainerRepository and TableRepository
handle optional column lists.

* fix(sftp): record file and directory FQNs that match what is stored

Enabling deleteStale exposed a latent bug in the SFTP source: the FQNs it
registers as "seen" during a run did not match the FQNs the create requests
actually store, so stale-entity deletion removed entities that had just been
ingested correctly.

Two mismatches:

- Files used the base register_record_file, which builds the FQN from a single
  context directory. For a file nested two levels deep that yields
  service.nested."f.csv" instead of service.data.nested."f.csv", and for a
  root-level file there is no context directory at all. Override it and pass the
  same path components the create request uses, with a direct _build for
  root-level files since fqn.build rejects an empty directory path.

- register_record_directory already built the correct path-based FQN on its main
  branch; its docstring now records why the FQN has to match, so the fallback is
  not "simplified" back to the bare name later.

These tests were passing before only because deleteStale returned 405 and no
deletion ever happened - with deletion working, six SFTP integration tests
covering nested directories and root-level files correctly began to fail.

* fix(sftp): fall back to the directory name when path components are empty

SftpDirectoryInfo.path is optional. yield_directory and register_record_directory
both fall back to `[directory_info.name]` when it is empty, but the file
registration path did not - so a nested file whose directory carried no path
components would register the root-level FQN and be deleted as stale straight
after being ingested. Use the same fallback everywhere.

* fix(sftp): suppress the known TopologyContext attribute error on the new line

TopologyContext attributes are populated dynamically, so basedpyright cannot see
drive_service. The ten pre-existing accesses in this file are carried in the
static-check baseline; a newly added line is not, and the baseline runs in
discard mode, which fails on any new error. Suppress it inline the same way
googledrive/connection.py does.

* refactor(api): deleteStale is a DELETE, not a PUT

Review feedback on #31375. `deleteStale` deletes entities, so it belongs on the
DELETE verb. Flipping only the four new Drive resources would leave them
unreachable from the shared ingestion client (which sent PUT), so the verb moves
on all 18 resources that declare the endpoint, plus both callers.

The seen-FQN set stays in the request body — a scope can hold thousands of FQNs,
which no query string can carry — so this is DELETE with an entity body. Jersey
routes the literal `/deleteStale` ahead of `/{id}`, the same way the 48 existing
literal-vs-template sibling routes already resolve.

A server that predates the endpoint now falls into `deleteById`, whose UUID path
param rejects "deleteStale" with a 404 — the status the client's legacy fallback
already keys on, so old-server behaviour is unchanged.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* fix(drive): correct GoogleDrive file FQNs and tolerate legacy null column FQNs

Two defects that only became visible once deleteStale started working.

GoogleDrive registered every file under an FQN that never matches the stored
one, so a working deleteStale soft-deletes all of them on the first run.
`file_request.directory` holds the parent's *full* FQN, which already starts
with the service name, but it was passed to fqn.build as a single path
component - producing svc."svc.data"."f.csv" instead of svc.data."f.csv". The
root-level branch was wrong too: it invented a "root" path segment, while those
files are created with directory=None and stored directly under the service.
Pass the path components below the service, and build the root-level FQN the
same way the create request does. Same class of bug as the SFTP one fixed
earlier in this branch; SharePoint has no connector implementation, so nothing
to fix there.

Columns persisted before their repository set column FQNs on the write path
carry a null FQN, so re-ingesting a file created by an older version NPE'd in
updateColumns. Compare with Objects.equals. The update itself repopulates the
FQN, so those rows repair themselves on the next ingestion and no backfill
migration is needed - the Drive entities have shipped since 1.11, so such rows
do exist in the field.

* fix(api): reject a null deleteStale body and skip null-FQN renames

Addresses two review findings.

Null stored column FQN inserted a null key into the rename map. The map is a
from -> to for rewriting lineage edges that already exist, so a column being
given an FQN for the first time has no prior edge to rewrite -- it is not a
rename and does not belong in the map. Skipping it also keeps a null key out of
what handleColumnLineageUpdates forwards to updateColumnLineage and
updateColumnsInUpstreamLineage. The Objects.equals tolerance stays: it exists
only so rows persisted before FileRepository set column FQNs on the write path
repair themselves on the next run instead of NPE'ing.

deleteStale carries its seen-FQN set in a DELETE body, which an aggressive proxy
can strip. An empty seen-set was already safe -- bulkDeleteStaleEntities treats
it as zero deletions rather than marking the whole scope stale -- and a body
removed outright was already a 400, since Jackson cannot map a zero-length
entity and JsonMappingExceptionMapper answers for it. The gap was the shape in
between: a body that parses cleanly to null binds the parameter to null, @Valid
on a null argument is a pass, the @NotNull constraints on the schema fields
never run, and validateScopeRequest NPEs into a 500. Mark the parameter @NotNull
so ConstraintViolationExceptionMapper answers 400 there too, and declare the
body via @RequestBody(required = true) so the generated spec documents the
endpoint as body-carrying.

The failure modes stay distinguishable: any dropped body fails the run loudly
with a client error, a genuinely empty seen-set warns and deletes nothing. The
ingestion client needs no change -- delete_stale_entities keys its legacy
fallback on 404 only, so a 400 propagates rather than silently re-hiding the
problem.

Applied to all 18 resources declaring the endpoint. BulkDeleteStaleIT covers
both dropped-body shapes; the null-body test asserts on the constraint message
so it cannot pass against the unfixed resource. BulkApi.deleteStaleRaw takes a
body publisher to send them.

* fix(ingestion): repair the two basedpyright errors from this branch

SourceAPIClient.delete wraps REST.delete, which gained a `json` parameter
ahead of `headers` when deleteStale moved to the DELETE verb. The wrapper
kept the old four-positional signature, so the override no longer matched
the base. Mirror the new signature and pass `json` through.

GoogleDriveSource.register_record_file reads context.drive_service, which
TopologyContext populates dynamically. The pre-existing accesses are carried
in the static-check baseline; a new line is not, and the baseline runs in
discard mode. Suppress it inline the same way the SFTP source does.

---------

Co-authored-by: mohitdeuex <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Co-authored-by: Pablo Takara <[email protected]>
Co-authored-by: IceS2 <[email protected]>

This branch was previously deployed

1 inactive deployment
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Drive connectors: every ingestion run fails, and re-runs cannot update files

3 participants