fix(ingest/adf): fix mypy errors hidden by CI's lint venvs (ADF SDK, okf smoke test)

SH
1d ago
+176-186

Summary

Two lint targets fail locally on master but pass in CI:

  • ./gradlew :metadata-ingestion:lint: 85 mypy errors in adf_probe.py (7) and tests/unit/azure_data_factory/test_adf_source.py (78).
  • ./gradlew :smoke-test:pythonLint: 2 mypy errors in tests/e2e/knowledge/test_okf_reimport.py:127-128.

This PR fixes them with type annotations only. Runtime behaviour does not change.

Why CI stays green

Both failures only appear when mypy can see packages that CI's lint venvs don't install:

  • metadata-ingestion: the lint venv installs .[dev], which doesn't include azure-mgmt-datafactory (it is in the azure-data-factory extra and full_test_dev_requirements). With ignore_missing_imports = yes, the whole SDK is Any to mypy, so CI's python-lint reports Success: no issues found in 3802 source files. A venv that also has the ADF extra installed (for example, to run the ADF unit tests) gets the real SDK types, and the errors show up.
  • smoke-test: :smoke-test:pythonLint doesn't depend on :metadata-ingestion:codegen, so in CI datahub.metadata.schema_classes is missing and is Any too. Locally, with the models generated, [*ownership.owners, *tags.tags] is inferred as list[DictWrapper], which has no attribution.

So these are latent errors in CI, not a mypy or stubs version difference. Making CI install the ADF extra or run codegen before smoke-test lint would surface this kind of error earlier. I left that out of this PR because it changes CI cost.

Where the errors came from

  • adf_probe.py: #20120 (probe support for pipeline sources). The SDK declares resource names as self.name = None, so mypy types ls.name and d.name as None, and the {ls.name: ls ...} comprehensions became dict[None, ...].
  • test_adf_source.py: #19494 introduced SimpleNamespace stand-ins for SDK models and linked_service=None. Later ADF PRs added more tests in the same style.
  • test_okf_reimport.py: #21101.

Changes

  • adf_probe.py: build the dataset and linked-service caches as Dict[str, ...] and cast(str, ...) the names. The comment explains why the casts are needed.
  • test_adf_source.py: a _fake(**attrs) -> Any helper replaces the bare SimpleNamespace(...) stand-ins. It still returns a SimpleNamespace. linked_service=None becomes _UNUSED_LINKED_SERVICE: Any = None, because _extract_table_name never reads that argument. There are no # type: ignore comments.
  • test_okf_reimport.py: annotate the joined list as List[Union[OwnerClass, TagAssociationClass]].

Testing

metadata-ingestion: mypy with azure-mgmt-datafactory==9.2.0 installed

master (aa03512a76):

$ ./gradlew :metadata-ingestion:lint     # after: uv pip install -e '.[azure-data-factory]'
...
tests/unit/azure_data_factory/test_adf_source.py:2754: error: Argument 2 to "_extract_query_column_lineage" of "AzureDataFactorySource" has incompatible type "SimpleNamespace"; expected "ActivityRun"  [arg-type]
Found 85 errors in 2 files (checked 3802 source files)

this branch:

$ ./gradlew :metadata-ingestion:lint
All checks passed!
3701 files already formatted
Success: no issues found in 3802 source files
BUILD SUCCESSFUL

I also ran mypy without the SDK installed (CI's setup): Success: no issues found on the ADF source and test packages.

smoke-test: mypy with the Python models generated

master:

$ ./gradlew :smoke-test:pythonLint
tests/e2e/knowledge/test_okf_reimport.py:127: error: "DictWrapper" has no attribute "attribution"  [attr-defined]
tests/e2e/knowledge/test_okf_reimport.py:128: error: "DictWrapper" has no attribute "attribution"  [attr-defined]
BUILD FAILED

this branch:

$ ./gradlew :smoke-test:pythonLint
Success: no issues found in 373 source files
BUILD SUCCESSFUL

Unit tests

$ pytest tests/unit/azure_data_factory
243 passed

I did not run the OKF smoke test, because it needs a running DataHub. The change there is a type annotation only.


Summary by cubic

Fixes 87 mypy errors that appear only when the ADF SDK and generated DataHub models are installed locally, not in CI's lint venvs.

The failures were latent: CI's :metadata-ingestion:lint doesn't install the azure-data-factory extra (so the SDK is Any to mypy), and :smoke-test:pythonLint doesn't run codegen (so datahub.metadata.schema_classes is missing). This PR adds the type annotations needed when those packages are present.

  • Uses cast(str, ...) for ADF resource names in adf_probe.py, since the SDK declares name as None; runtime behavior is unchanged.
  • Replaces bare SimpleNamespace(...) stand-ins in test_adf_source.py with a _fake(**attrs) -> Any helper.
  • Annotates the joined owners/tags list in test_okf_reimport.py as List[Union[OwnerClass, TagAssociationClass]].

🤖 Opened with cclaude on behalf of @shirshanka