chore(python): modernize typing and enforce lazy logging - #31643
Conversation
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
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 |
🔴 Playwright Results — workflow failedValidated commit ✅ 0 passed · ❌ 0 failed · 🟡 0 flaky · ⏭️ 0 skipped · 🧰 0 lifecycle flaky Pipeline and setup failures (6)
Performance⚪ Performance metrics unavailable; see the CI and reporting failures above.
How to debug locally# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip # view trace |
| try to parse it or log the given message | ||
| """ | ||
| logger.debug(f"Parsing message: [{message}]") | ||
| logger.debug(f"Parsing message: [{message}]") # noqa: G004 |
| raise InvalidWorkflowException("Missing type in the serviceConnection config") | ||
|
|
||
| logger.debug(f"Error parsing the Workflow Configuration for {source_type} ingestion") | ||
| logger.debug(f"Error parsing the Workflow Configuration for {source_type} ingestion") # noqa: G004 |
| ): | ||
| secret_id = self._secret_value.replace(SECRET, "") | ||
| logger.info(f"Getting secret value for {secret_id}") | ||
| logger.info(f"Getting secret value for {secret_id}") # noqa: G004 |
| secret_value = SecretsManagerFactory().get_secrets_manager().get_string_value(secret_id) | ||
| except Exception as exc: | ||
| logger.error(f"Secret value [{secret_id}] not present in the configured secrets manager: {exc}") | ||
| logger.error(f"Secret value [{secret_id}] not present in the configured secrets manager: {exc}") # noqa: G004 |
| @@ -107,11 +107,11 @@ | |||
| """ | |||
| try: | |||
| secret: KeyVaultSecret = self.client.get_secret(secret_id) | |||
| logger.debug(f"Got value for secret {secret_id}") | |||
| logger.debug(f"Got value for secret {secret_id}") # noqa: G004 | |||
| @@ -134,24 +133,24 @@ | |||
| # Kubernetes stores secret data as base64 encoded | |||
| if secret.data and "value" in secret.data: | |||
| secret_value = base64.b64decode(secret.data["value"]).decode("utf-8") | |||
| logger.debug(f"Got value for secret {secret_id}") | |||
| logger.debug(f"Got value for secret {secret_id}") # noqa: G004 | |||
| return secret_value | ||
| logger.warning(f"Secret {secret_id} exists but has no 'value' key") | ||
| logger.warning(f"Secret {secret_id} exists but has no 'value' key") # noqa: G004 |
| return None # noqa: TRY300 | ||
|
|
||
| except ApiException as exc: | ||
| if exc.status == 404: | ||
| logger.debug(f"Secret {secret_id} not found") | ||
| logger.debug(f"Secret {secret_id} not found") # noqa: G004 |
| return None | ||
| logger.debug(traceback.format_exc()) | ||
| logger.error(f"Could not get the secret value of {secret_id} due to [{exc}]") | ||
| logger.error(f"Could not get the secret value of {secret_id} due to [{exc}]") # noqa: G004 |
| raise exc # noqa: TRY201 | ||
| except Exception as exc: | ||
| logger.debug(traceback.format_exc()) | ||
| logger.error(f"Could not get the secret value of {secret_id} due to [{exc}]") | ||
| logger.error(f"Could not get the secret value of {secret_id} due to [{exc}]") # noqa: G004 |
|
Too many files changed for review (1022 files, 100 file limit). |
| @if rg -n --glob '*.py' '[#][[:space:]]*noqa:[^#]*(UP006|UP007|UP035|UP045)' $(INGESTION_DIR)/ $(ROOT_DIR)/openmetadata-airflow-apis/; then \ | ||
| echo "Do not suppress modern typing rules; fix the annotation instead." >&2; \ | ||
| exit 1; \ | ||
| fi | ||
| ruff check --ignore-noqa --select $(MODERN_TYPING_RULES) $(INGESTION_DIR)/ $(ROOT_DIR)/openmetadata-airflow-apis/ --config $(INGESTION_DIR)/pyproject.toml |
There was a problem hiding this comment.
💡 Quality: noqa-scan guard silently skips if ripgrep is unavailable
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.
Was this helpful? React with 👍 / 👎
Code Review 👍 Approved with suggestions 0 resolved / 1 findingsModernizes Python typing annotations and enforces lazy logging formatting across ingestion codebases. Consider adding a fallback for the noqa-scan guard when ripgrep is unavailable. 💡 Quality: noqa-scan guard silently skips if ripgrep is unavailableThe new guard in ingestion/Makefile ( 🤖 Prompt for agentsOptionsDisplay: compact → Showing less information. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
Describe your changes:
Modernizes Python annotations covered by
UP006,UP007,UP035, andUP045, including generated Pydantic classes duringmake generate. CI now rejects both violations and new# noqasuppressions for those rules.Enables only
G004in Ruff's selected rules. The current baseline of 2,536 logging f-string violations across 416 files is preserved with targeted# noqa: G004directives, while new logging f-strings fail lint and must use lazy%-style formatting.Type of change:
High-level design:
make generate.--ignore-noqaplus an explicit directive scan so suppressions cannot bypass CI.G004globally 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
UP006,UP007,UP035, orUP045violations, including suppressed violations.Unit tests
python -m compileall -q ingestion/src openmetadata-airflow-apismake py_format_checkF401,UP006,UP007,UP035,UP045The 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
Ingestion integration tests
Playwright (UI) tests
Manual testing performed
UI screen recording / screenshots:
Not applicable.
Checklist:
Fixes <issue-number>: <short explanation>.Fixes #<issue-number>above.