Skip to content

chore(python): modernize typing and enforce lazy logging - #31643

Merged
pmbrull merged 11 commits into
mainfrom
chore/modernize-python-typing-logging
Sep 2, 2026
Merged

pmbrull merged 11 commits into
mainfrom
chore/modernize-python-typing-logging

Conversation

@IceS2

@IceS2 IceS2 commented Aug 17, 2026 •

Copy link
Copy Markdown
Collaborator

Describe your changes:

Modernizes Python annotations covered by UP006, UP007, UP035, and UP045, including generated Pydantic classes during make generate. CI now rejects both violations and new # noqa suppressions for those rules.

Enables only G004 in Ruff's selected rules. The current baseline of 2,536 logging f-string violations across 416 files is preserved with targeted # noqa: G004 directives, while new logging f-strings fail lint and must use lazy %-style formatting.

Type of change:

  • Improvement

High-level design:

  • Apply Ruff's Python 3.10 typing modernization across handwritten code.
  • Run the same modernization over generated Python after make generate.
  • Keep the four typing rules out of Ruff's global selection, but enforce them with --ignore-noqa plus an explicit directive scan so suppressions cannot bypass CI.
  • Select G004 globally and grandfather the current baseline with targeted directives so future logging code must be lazy-formatted.

This is a mechanical migration; it does not change supported Python versions or public APIs.

Tests:

Use cases covered

  • Existing Python code contains no UP006, UP007, UP035, or UP045 violations, including suppressed violations.
  • New suppressions for those four rules are rejected.
  • New logging f-strings are rejected while the current baseline remains accepted.
  • Generated Python is modernized on regeneration.

Unit tests

  • Existing focused ingestion suites: 95 passed.
  • python -m compileall -q ingestion/src openmetadata-airflow-apis
  • make py_format_check
  • Generated Python targeted Ruff check for F401,UP006,UP007,UP035,UP045

The complete unit-test tree could not be collected in the reused local environment because optional connector dependencies are absent and its installed spaCy/Thinc build is binary-incompatible with NumPy.

Backend integration tests

  • Not applicable (no backend API changes).

Ingestion integration tests

  • Not applicable (mechanical typing and lint-policy migration).

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

  • Not applicable.

UI screen recording / screenshots:

Not applicable.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>.
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.
  • For JSON Schema changes: not applicable, no schema changes.
  • For UI changes: not applicable, no UI changes.

@IceS2
IceS2 requested a review from a team as a code owner August 17, 2026 13:57
Copilot AI lite review requested due to automatic review settings August 17, 2026 13:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@github-actions github-actions Bot added Ingestion safe to test Add this label to run secure Github workflows on PRs labels Aug 17, 2026
@github-actions

github-actions Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

✅ Playwright Results — workflow succeeded

Validated commit c178777e9b09f45e704173da3e8eed8e16ff9064 in Playwright run 33598172401, attempt 1.

✅ 616 passed · ❌ 0 failed · 🟡 2 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) 56m 22s

⏱️ Max setup 4m 36s · max shard execution 15m 27s · max shard-job elapsed before upload 19m 44s · reporting 6s

🌐 220.61 requests/attempt · 2.75 app boots/UI scenario · 7.12% common-shard skew

Optimization targets still in progress:

  • Browser traffic was 220.61 requests per attempt (convergence target: fewer than 200).
  • Application boot ratio was 2.75 per UI scenario (1785 boots / 650 scenarios; convergence target: at most 1).
Shard Passed Failed Flaky Skipped Lifecycle failed Lifecycle flaky
✅ Shard chromium-01 130 0 0 0 0 0
✅ Shard chromium-02 133 0 0 0 0 0
🟡 Shard chromium-03 135 0 1 0 0 0
✅ Shard data-asset-rules-01 63 0 0 0 0 0
✅ Shard domain-isolation-01 16 0 0 0 0 0
✅ Shard global-state-01 34 0 0 0 0 0
✅ Shard ingestion-01 30 0 0 0 0 0
🟡 Shard ingestion-02 33 0 1 0 0 0
✅ Shard reindex-01 2 0 0 0 0 0
✅ Shard search-01 11 0 0 0 0 0
✅ Shard search-rbac-01 29 0 0 0 0 0
🟡 2 flaky test(s) (passed on retry)
  • Pages/Entity.spec.ts › Announcement create, edit & delete (shard chromium-03, 1 retry)
  • Features/DataQuality/DataQuality.spec.ts › Pagination functionality in test cases list (shard ingestion-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

@IceS2 IceS2 added this to Shipping Aug 17, 2026
@greptile-apps

greptile-apps Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Too many files changed for review (987 files, 100 file limit).

Comment thread ingestion/Makefile Resolved
Copilot AI review requested due to automatic review settings August 17, 2026 16:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

…n-typing-logging

# Conflicts:
#	ingestion/src/metadata/ingestion/models/topology.py
#	ingestion/src/metadata/ingestion/ometa/mixins/feed_mixin.py
#	ingestion/src/metadata/ingestion/source/api/rest/metadata.py
#	ingestion/src/metadata/ingestion/source/dashboard/tableau/client.py
#	ingestion/src/metadata/ingestion/source/database/db2/utils.py
#	ingestion/src/metadata/ingestion/source/database/glue/metadata.py
#	ingestion/src/metadata/ingestion/source/database/oracle/connection.py
#	ingestion/src/metadata/ingestion/source/database/trino/metadata.py
#	ingestion/src/metadata/ingestion/source/mlmodel/mlflow/metadata.py
#	ingestion/src/metadata/ingestion/source/pipeline/databrickspipeline/kafka_parser.py
#	ingestion/src/metadata/ingestion/source/pipeline/databrickspipeline/metadata.py
#	ingestion/src/metadata/ingestion/source/pipeline/databrickspipeline/models.py
#	ingestion/src/metadata/pii/scanners/ner_scanner.py
#	ingestion/src/metadata/pii/tag_analyzer.py
#	ingestion/src/metadata/profiler/interface/pandas/profiler_interface.py
#	ingestion/tests/integration/profiler/test_sqa_profiler.py
…n-typing-logging

# Conflicts:
#	ingestion/src/metadata/ingestion/source/pipeline/kafkaconnect/client.py
#	ingestion/src/metadata/ingestion/source/pipeline/kafkaconnect/metadata.py
#	ingestion/src/metadata/pii/algorithms/classifiers.py
#	ingestion/src/metadata/pii/algorithms/preprocessing.py
Copilot AI review requested due to automatic review settings September 2, 2026 06:11
@gitar-bot

gitar-bot Bot commented Sep 2, 2026

Copy link
Copy Markdown
Code Review ⚠️ Changes requested 1 resolved / 4 findings

Modernizes Python 3.10+ typing annotations and enforces lazy logging to prevent future f-string violations in logs. Three issues must be resolved before merge: debug log messages incorrectly report "Error parsing..." on successful parse paths in three files, DynamoDB's Items field was made nullable but callers iterate it expecting a list, and a test dataclass field is typed as non-optional list but defaults to None. Revert the log messages to the original wording, restore Items to a non-optional list with a factory default, and fix the type annotation or default value in the test dataclass.

⚠️ Bug: Debug log reworded to falsely report an error on success path

📄 ingestion/src/metadata/ingestion/api/parser.py:410 📄 ingestion/src/metadata/ingestion/api/parser.py:613 📄 openmetadata-airflow-apis/openmetadata_managed_apis/utils/parser.py:88

These logger.debug calls fire on the normal, successful parse path (right after confirming source_type is present and before any parsing), yet the message was changed from "Parsing the workflow configuration for %s ingestion" to "Error parsing the Workflow Configuration for %s ingestion". It now emits "Error parsing..." during ordinary, error-free parsing, which is misleading during debugging and is out of scope for a mechanical typing/logging migration. Revert the wording back to the original "Parsing the workflow configuration for %s ingestion".

Restore the original, accurate log message.
logger.debug("Parsing the workflow configuration for %s ingestion", source_type)
⚠️ Bug: DynamoDB Items field now nullable, breaking iteration contract

📄 ingestion/src/metadata/ingestion/source/database/dynamodb/models.py:25

Changing Items: list[dict] = Field(default_factory=list) to Items: list[dict] | None = [] makes the field accept None. Callers that iterate response.Items (e.g. paginated scan/query handling) will raise TypeError: 'NoneType' object is not iterable if a DynamoDB response yields Items: null, whereas the previous type guaranteed a list. This is a semantic change unrelated to the UP006/UP007/UP035/UP045 typing rules. Keep the field non-optional with a proper factory default.

Restore non-nullable list with default_factory (re-add Field import).
Items: list[dict] = Field(default_factory=list)
LastEvaluatedKey: Any | None = None
💡 Quality: Dataclass field typed list but defaulted to None

📄 ingestion/tests/integration/trino/test_profiler.py:57

expected_column_profiles: list[ColumnProfile] = None annotates a non-optional list yet defaults to None, which is type-inconsistent and will be flagged by type checkers. If the intent is optional, annotate it as list[ColumnProfile] | None = None; if it should always be a list, use field(default_factory=list).

Make the annotation match the None default.
expected_column_profiles: list[ColumnProfile] | None = None
✅ 1 resolved
✅ Quality: noqa-scan guard silently skips if ripgrep is unavailable

📄 ingestion/Makefile:63-67
The new guard in ingestion/Makefile (if rg -n ... '(UP006|UP007|UP035|UP045)'; then ...exit 1; fi) relies on rg's exit code: 0 = matches found (fail), 1 = no matches (pass). But if rg is missing or errors, it exits with code 2, which the if treats as falsey and the build proceeds — silently disabling the anti-suppression enforcement rather than failing loudly. rg is used elsewhere so this is low-risk, but pinning rg as an explicit prerequisite or checking command -v rg before the scan would make the guard fail-closed. Minor; the primary ruff check --ignore-noqa --select step below still enforces the rules regardless.

🤖 Prompt for agents
Code Review: Modernizes Python 3.10+ typing annotations and enforces lazy logging to prevent future f-string violations in logs. Three issues must be resolved before merge: debug log messages incorrectly report "Error parsing..." on successful parse paths in three files, DynamoDB's `Items` field was made nullable but callers iterate it expecting a list, and a test dataclass field is typed as non-optional list but defaults to `None`. Revert the log messages to the original wording, restore `Items` to a non-optional list with a factory default, and fix the type annotation or default value in the test dataclass.

1. ⚠️ Bug: Debug log reworded to falsely report an error on success path
   Files: ingestion/src/metadata/ingestion/api/parser.py:410, ingestion/src/metadata/ingestion/api/parser.py:613, openmetadata-airflow-apis/openmetadata_managed_apis/utils/parser.py:88

   These `logger.debug` calls fire on the normal, successful parse path (right after confirming `source_type` is present and before any parsing), yet the message was changed from "Parsing the workflow configuration for %s ingestion" to "Error parsing the Workflow Configuration for %s ingestion". It now emits "Error parsing..." during ordinary, error-free parsing, which is misleading during debugging and is out of scope for a mechanical typing/logging migration. Revert the wording back to the original "Parsing the workflow configuration for %s ingestion".

   Fix (Restore the original, accurate log message.):
   logger.debug("Parsing the workflow configuration for %s ingestion", source_type)

2. ⚠️ Bug: DynamoDB Items field now nullable, breaking iteration contract
   Files: ingestion/src/metadata/ingestion/source/database/dynamodb/models.py:25

   Changing `Items: list[dict] = Field(default_factory=list)` to `Items: list[dict] | None = []` makes the field accept `None`. Callers that iterate `response.Items` (e.g. paginated scan/query handling) will raise `TypeError: 'NoneType' object is not iterable` if a DynamoDB response yields `Items: null`, whereas the previous type guaranteed a list. This is a semantic change unrelated to the UP006/UP007/UP035/UP045 typing rules. Keep the field non-optional with a proper factory default.

   Fix (Restore non-nullable list with default_factory (re-add Field import).):
   Items: list[dict] = Field(default_factory=list)
   LastEvaluatedKey: Any | None = None

3. 💡 Quality: Dataclass field typed list but defaulted to None
   Files: ingestion/tests/integration/trino/test_profiler.py:57

   `expected_column_profiles: list[ColumnProfile] = None` annotates a non-optional list yet defaults to `None`, which is type-inconsistent and will be flagged by type checkers. If the intent is optional, annotate it as `list[ColumnProfile] | None = None`; if it should always be a list, use `field(default_factory=list)`.

   Fix (Make the annotation match the None default.):
   expected_column_profiles: list[ColumnProfile] | None = None

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

There are at least CI-blocking typing issues in the updated annotations (e.g., a non-optional list[...] field defaulting to None) that should be corrected before merge.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (1)

ingestion/src/metadata/ingestion/ometa/ttl_cache.py:28

  • TTLCache uses an unbounded dict and only prunes expired entries on __contains__. If many distinct keys are added without being checked again, this can grow without bound. Add eager expiry pruning on add() and a hard max size to keep memory bounded.
  • Files reviewed: 298/987 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment on lines 86 to 90
raise InvalidWorkflowException("Missing type in the serviceConnection config")

logger.debug(f"Error parsing the Workflow Configuration for {source_type} ingestion")
logger.debug("Error parsing the Workflow Configuration for %s ingestion", source_type)

service_type = get_service_type(source_type)
Copilot AI review requested due to automatic review settings September 2, 2026 06:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

A few updated type hints are internally inconsistent with runtime behavior (e.g., Flink client return type, DynamoDB response model, and an integration-test dataclass default), which will break type-checking and can cause runtime errors.

Review details
  • Files reviewed: 298/987 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@sonarqubecloud

sonarqubecloud Bot commented Sep 2, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed for 'open-metadata-airflow-apis'

Failed conditions
0.0% Coverage on New Code (required ≥ 20%)

See analysis details on SonarQube Cloud

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

Ingestion safe to test Add this label to run secure Github workflows on PRs

Projects

Status: Done ✅

Development

Successfully merging this pull request may close these issues.

4 participants