fix(ingest/adf): fix mypy errors hidden by CI's lint venvs (ADF SDK, okf smoke test)
Summary
Two lint targets fail locally on master but pass in CI:
./gradlew :metadata-ingestion:lint: 85 mypy errors inadf_probe.py(7) andtests/unit/azure_data_factory/test_adf_source.py(78)../gradlew :smoke-test:pythonLint: 2 mypy errors intests/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 includeazure-mgmt-datafactory(it is in theazure-data-factoryextra andfull_test_dev_requirements). Withignore_missing_imports = yes, the whole SDK isAnyto mypy, so CI'spython-lintreportsSuccess: 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:pythonLintdoesn't depend on:metadata-ingestion:codegen, so in CIdatahub.metadata.schema_classesis missing and isAnytoo. Locally, with the models generated,[*ownership.owners, *tags.tags]is inferred aslist[DictWrapper], which has noattribution.
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 asself.name = None, so mypy typesls.nameandd.nameasNone, and the{ls.name: ls ...}comprehensions becamedict[None, ...].test_adf_source.py: #19494 introducedSimpleNamespacestand-ins for SDK models andlinked_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 asDict[str, ...]andcast(str, ...)the names. The comment explains why the casts are needed.test_adf_source.py: a_fake(**attrs) -> Anyhelper replaces the bareSimpleNamespace(...)stand-ins. It still returns aSimpleNamespace.linked_service=Nonebecomes_UNUSED_LINKED_SERVICE: Any = None, because_extract_table_namenever reads that argument. There are no# type: ignorecomments.test_okf_reimport.py: annotate the joined list asList[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 inadf_probe.py, since the SDK declaresnameasNone; runtime behavior is unchanged. - Replaces bare
SimpleNamespace(...)stand-ins intest_adf_source.pywith a_fake(**attrs) -> Anyhelper. - Annotates the joined owners/tags list in
test_okf_reimport.pyasList[Union[OwnerClass, TagAssociationClass]].
🤖 Opened with cclaude on behalf of @shirshanka