2026-04-06 04:56:06 +00:00
|
|
|
# Copyright 2025 Collate
|
|
|
|
|
# Licensed under the Collate Community License, Version 1.0 (the "License");
|
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
|
# https://github.com/open-metadata/OpenMetadata/blob/main/ingestion/LICENSE
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
Tests for GCP CloudSQL MySQL connection handling
|
|
|
|
|
"""
|
chore(ingestion): migrate to ruff for format + isort + unused-import (#27739)
* chore(ingestion): replace black/isort/pycln with ruff
- Swap formatter + import-sorter + unused-import tooling for ruff
(line-length 120, target py3.10) in ingestion + openmetadata-airflow-apis
- Drop dead [tool.mypy] config; basedpyright is the active type checker
- Bump requires-python to >=3.10 to match noxfile and CLAUDE.md (3.9 is
documented as broken on Mac in noxfile.py)
- Bump pre-commit-hooks v2.3 -> v5.0; the new check-json catches four
pre-existing JSON issues now excluded with an inline TODO
- Update Makefile py_format / py_format_check targets to call ruff
* chore(ingestion): grandfather ruff lint violations and apply ruff format
- 253 noqa markers added via 'ruff check --add-noqa' across 128 files,
freezing existing violations so this PR is a tooling-only swap. Per-rule
cleanup tracked in the TODO comment in ingestion/pyproject.toml.
- Bulk reformat from black 22.3 -> ruff format @ line-length 120.
Cosmetic only: imports balanced (-32/+32), structural keywords balanced
(-2221/+2221), no logic changes.
- Star-import rules (F403/F405) globally ignored; refactoring wildcard
imports across connectors is a separate effort.
* chore(ingestion): fix pylint findings surfaced after ruff format
- filters.py: drop redundant parens around re.match(...) in `if`
(C0325 superfluous-parens) — exposed when ruff format unwrapped them
- nosql_adaptor.py: move `# pylint: disable=unused-argument` from the
`column:` line to the `def` line so it covers `table` too (W0613) —
scope was line-based, lost when ruff split params onto multiple lines
- action1xx.py: replace `arguments-differ` with `signature-differs` in
the disable directive (was always wrong code) and drop the now-useless
`unused-argument` suppression (I0021)
* fix(ingestion): make ruff extend-exclude robust to multi-root invocations
CI's `make py_format_check` runs from the repo root and passes both
`ingestion/` and `./openmetadata-airflow-apis/` to ruff in a single
invocation. With multiple root paths, ruff's parallel file discovery
races on extend-exclude matching against the project root, so files
under `ingestion/src/metadata/generated/` were intermittently scanned
and produced ~830 I001 violations.
20-run repro: 10/20 fail without the fix, 20/20 pass with the fix.
Each excluded directory now appears twice in extend-exclude:
- the project-root-relative pattern (cwd = ingestion/)
- the prefixed pattern (cwd = repo root, multi-root invocation)
* chore(ingestion): address gitar-bot findings + cross-version pylint disable
- openmetadata-airflow-apis/pyproject.toml: switch coverage to module-name
source + [tool.coverage.paths] glob remap (matches the ingestion pattern).
Drops the hardcoded `env/lib/python3.9/site-packages/...` source path,
which broke after the requires-python bump to 3.10. (Finding 1)
- ingestion/setup.py: remove dead python_version<'3.9' / >='3.9' guards on
mysql-connector-python and testcontainers; promote locust to a regular
test dep (was conditionally added under sys.version_info >= (3, 9)). Also
remove the now-unused `import sys`. (Finding 3)
- ingestion/src/metadata/great_expectations/action1xx.py: cover both
arguments-differ (great_expectations 0.18.x parent) and signature-differs
(great_expectations 1.x parent) in the pylint disable comment, since
CI installs 0.18.x and local often has 1.x. unused-argument covers the
unused action_context. The opposite rule fires as I0021 useless-suppression
on each environment, which is informational and does not affect pylint's
exit code.
2026-04-27 08:05:28 +00:00
|
|
|
|
2026-04-06 04:56:06 +00:00
|
|
|
import sys
|
|
|
|
|
from types import ModuleType
|
|
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
from metadata.generated.schema.entity.services.connections.database.common.gcpCloudSqlConfig import (
|
|
|
|
|
GcpCloudsqlConfigurationSource,
|
|
|
|
|
)
|
|
|
|
|
from metadata.generated.schema.entity.services.connections.database.mysqlConnection import (
|
|
|
|
|
MysqlConnection,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
_NAMESPACE_MODULES = (
|
|
|
|
|
"google",
|
|
|
|
|
"google.cloud",
|
|
|
|
|
"google.cloud.sql",
|
|
|
|
|
"google.cloud.sql.connectors",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
|
def mock_connector():
|
|
|
|
|
"""Inject a fake google.cloud.sql.connectors module into sys.modules
|
|
|
|
|
so the lazy import inside _get_cloudsql_engine works without
|
|
|
|
|
installing cloud-sql-python-connector."""
|
|
|
|
|
connector_instance = MagicMock()
|
|
|
|
|
connector_cls = MagicMock(return_value=connector_instance)
|
|
|
|
|
|
|
|
|
|
connectors_mod = ModuleType("google.cloud.sql.connectors")
|
|
|
|
|
connectors_mod.Connector = connector_cls
|
|
|
|
|
|
|
|
|
|
originals = {k: sys.modules.get(k) for k in _NAMESPACE_MODULES}
|
|
|
|
|
|
|
|
|
|
sys.modules.setdefault("google", ModuleType("google"))
|
|
|
|
|
sys.modules.setdefault("google.cloud", ModuleType("google.cloud"))
|
|
|
|
|
sys.modules.setdefault("google.cloud.sql", ModuleType("google.cloud.sql"))
|
|
|
|
|
sys.modules["google.cloud.sql.connectors"] = connectors_mod
|
|
|
|
|
|
|
|
|
|
yield connector_cls, connector_instance
|
|
|
|
|
|
|
|
|
|
for key, val in originals.items():
|
|
|
|
|
if val is None:
|
|
|
|
|
sys.modules.pop(key, None)
|
|
|
|
|
else:
|
|
|
|
|
sys.modules[key] = val
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _make_mysql_connection(connection):
|
|
|
|
|
from metadata.ingestion.source.database.mysql.connection import MySQLConnection
|
|
|
|
|
|
|
|
|
|
mysql_conn = MySQLConnection.__new__(MySQLConnection)
|
|
|
|
|
mysql_conn.service_connection = connection
|
|
|
|
|
return mysql_conn
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestMySQLCloudSQLConnection:
|
chore(ingestion): migrate to ruff for format + isort + unused-import (#27739)
* chore(ingestion): replace black/isort/pycln with ruff
- Swap formatter + import-sorter + unused-import tooling for ruff
(line-length 120, target py3.10) in ingestion + openmetadata-airflow-apis
- Drop dead [tool.mypy] config; basedpyright is the active type checker
- Bump requires-python to >=3.10 to match noxfile and CLAUDE.md (3.9 is
documented as broken on Mac in noxfile.py)
- Bump pre-commit-hooks v2.3 -> v5.0; the new check-json catches four
pre-existing JSON issues now excluded with an inline TODO
- Update Makefile py_format / py_format_check targets to call ruff
* chore(ingestion): grandfather ruff lint violations and apply ruff format
- 253 noqa markers added via 'ruff check --add-noqa' across 128 files,
freezing existing violations so this PR is a tooling-only swap. Per-rule
cleanup tracked in the TODO comment in ingestion/pyproject.toml.
- Bulk reformat from black 22.3 -> ruff format @ line-length 120.
Cosmetic only: imports balanced (-32/+32), structural keywords balanced
(-2221/+2221), no logic changes.
- Star-import rules (F403/F405) globally ignored; refactoring wildcard
imports across connectors is a separate effort.
* chore(ingestion): fix pylint findings surfaced after ruff format
- filters.py: drop redundant parens around re.match(...) in `if`
(C0325 superfluous-parens) — exposed when ruff format unwrapped them
- nosql_adaptor.py: move `# pylint: disable=unused-argument` from the
`column:` line to the `def` line so it covers `table` too (W0613) —
scope was line-based, lost when ruff split params onto multiple lines
- action1xx.py: replace `arguments-differ` with `signature-differs` in
the disable directive (was always wrong code) and drop the now-useless
`unused-argument` suppression (I0021)
* fix(ingestion): make ruff extend-exclude robust to multi-root invocations
CI's `make py_format_check` runs from the repo root and passes both
`ingestion/` and `./openmetadata-airflow-apis/` to ruff in a single
invocation. With multiple root paths, ruff's parallel file discovery
races on extend-exclude matching against the project root, so files
under `ingestion/src/metadata/generated/` were intermittently scanned
and produced ~830 I001 violations.
20-run repro: 10/20 fail without the fix, 20/20 pass with the fix.
Each excluded directory now appears twice in extend-exclude:
- the project-root-relative pattern (cwd = ingestion/)
- the prefixed pattern (cwd = repo root, multi-root invocation)
* chore(ingestion): address gitar-bot findings + cross-version pylint disable
- openmetadata-airflow-apis/pyproject.toml: switch coverage to module-name
source + [tool.coverage.paths] glob remap (matches the ingestion pattern).
Drops the hardcoded `env/lib/python3.9/site-packages/...` source path,
which broke after the requires-python bump to 3.10. (Finding 1)
- ingestion/setup.py: remove dead python_version<'3.9' / >='3.9' guards on
mysql-connector-python and testcontainers; promote locust to a regular
test dep (was conditionally added under sys.version_info >= (3, 9)). Also
remove the now-unused `import sys`. (Finding 3)
- ingestion/src/metadata/great_expectations/action1xx.py: cover both
arguments-differ (great_expectations 0.18.x parent) and signature-differs
(great_expectations 1.x parent) in the pylint disable comment, since
CI installs 0.18.x and local often has 1.x. unused-argument covers the
unused action_context. The opposite rule fires as I0021 useless-suppression
on each environment, which is informational and does not affect pylint's
exit code.
2026-04-27 08:05:28 +00:00
|
|
|
@patch("metadata.ingestion.source.database.mysql.connection.create_generic_db_connection")
|
2026-04-06 04:56:06 +00:00
|
|
|
def test_cloudsql_password_auth(self, mock_create_conn, mock_connector):
|
chore(ingestion): drop pylint, expand ruff (#27774)
* chore(ingestion): drop pylint, expand ruff to Stage 2c
Replace pylint with a coherent ruff-only stack (Stage 2c of the modernize
roadmap). Pylint is dropped from dev deps and CI workflows; ruff selected
ruleset expanded to ~22 families covering style, bug catchers, hygiene,
and the pylint port (PLE/PLC/PLW/PLR with the noisy "too-many-X"
complexity caps + magic-value disabled).
What's selected (with rationale in pyproject.toml):
E, W, F, I, N — style + correctness baseline + naming
UP — pyupgrade (py>=3.10 modernizations)
B, C4, C90, RET, SIM, TRY — bug catchers
PIE, ICN, T20, TC, TID, PTH, PERF — hygiene
PLE, PLC, PLW, PLR — pylint port (PLR complexity caps ignored)
RUF — ruff-native (incl. RUF100 unused-noqa)
What's removed:
- .pylintrc (root) — duplicate of the ingestion pylint config
- [tool.pylint.*] block in ingestion/pyproject.toml (~140 lines)
- ingestion/plugins/{print_checker,import_checker}.py + tests + README
(replaced by built-in T20 + TID251 banned-api respectively)
- pylint dep from ingestion/setup.py and openmetadata-airflow-apis/pyproject.toml
- `make lint` Makefile target + the pylint invocation in py_format_check
- dead pylint TODO comment + ignored test entry in noxfile.py
Cwd-stable config: ruff is invoked both from the repo root (pre-commit,
CI) and from ingestion/ (`make py_format_check`). The `src`,
`extend-exclude`, and per-file-ignores entries are listed twice — once
relative to ingestion/ and once with the `ingestion/` prefix — so
first-party isort detection and exclusions match in both invocations.
Grandfathering: ran `ruff check --add-noqa` once + format-stable
iteration. ~12,130 noqa directives across ~1,400 files. Cleanup is
deferred to follow-up PRs that drop noqas one rule at a time.
Documentation sweep: replaced `make lint` references in CLAUDE.md,
AGENTS.md, DEVELOPER.md, copilot-instructions, and 6 SKILL files with
the apply+verify shape `make py_format && make py_format_check`.
`make py_format` is NOT a strict superset of pylint — it only applies
auto-fixable violations; `make py_format_check` catches the rest.
Basedpyright baseline regenerated: ruff format reflowed multi-line
signatures in ~70 files, shifting type-error column positions. The
basedpyright baseline matches by (file path, error code, range), so
column shifts caused 19 entries to mis-align. Net diff is small
(154 lines in/out of the 13MB baseline.json) — purely positional.
Verified locally:
- make py_format_check → All checks passed
- nox --no-venv -s static-checks → 0 errors, 0 warnings, 0 notes
* chore(ingestion): finish ruff swap — nox lint session + skill docs
Three remaining stale-tooling references after Stage 2c:
- `ingestion/noxfile.py` `lint` session was still calling `black --check`,
`isort --check-only`, `pycln --diff`. Those tools aren't installed
anywhere (we dropped them from dev deps). Replace with the ruff
equivalents that mirror `make py_format_check`.
- `skills/standards/code_style.md`: stack listed as `black + isort +
pycln`; line length claimed 88 (black default). Both wrong: stack is
ruff, line length is 120.
- `skills/connector-building/SKILL.md`: `make py_format` comment said
`# black + isort + pycln`. Same swap.
* chore(ingestion): keep main's baseline + globally ignore TRY400
Per gitar-bot's review on PR #27774:
1. Main's PR #27728 promoted ~60 `logger.warning()` → `logger.error()`
inside `except` blocks. Those changes landed on main with their own
baseline updates. Our PR doesn't promote anything — the merge from
origin/main brought those `error` calls along with their baseline
entries.
The bot interpreted the `# noqa: TRY400` we added next to those lines
as us silencing the rule case-by-case. Cleaner: globally ignore
TRY400 in pyproject.toml, with a comment explaining why the codebase's
`logger.error(...)` + separate `logger.debug(traceback.format_exc())`
pattern is intentional. Strip ~430 per-line `# noqa: TRY400` markers
from source.
2. Document that `S101` in `per-file-ignores` is a forward-looking
entry — flake8-bandit (`S`) is not yet selected, so the rule is
no-op today; the entry stays so when `S` lands later, tests don't
immediately error.
Reverts the platform pin and Linux Docker–generated baseline. Keep
main's baseline intact and let CI surface the exact column-shifted
entries; the team will decide whether to fix in-place (revert format
on affected files) or add per-line `# pyright: ignore` markers.
* chore(ingestion): regen baseline for new connector type debt
Main's baseline was stale relative to recently-added connectors
(McpConnection, CustomDriveConnection) that lack common attributes
like `hostPort`, `database`, `catalog` etc. — all sites that access
those attributes via the union-typed `serviceConnection.root.config`
fire `reportAttributeAccessIssue` errors that aren't baselined.
71 errors + 58 warnings absorbed. Local macOS regen; pushing to see
CI's drift count. Per the basedpyright-baseline-and-ci PR experience,
macOS↔Linux column drift on this size of regen has historically been
1-7 residuals.
2026-04-28 05:21:59 +00:00
|
|
|
mock_connector_cls, mock_connector_inst = mock_connector # noqa: RUF059
|
2026-04-06 04:56:06 +00:00
|
|
|
mock_create_conn.return_value = MagicMock()
|
|
|
|
|
|
|
|
|
|
connection = MysqlConnection(
|
|
|
|
|
hostPort="my-project:us-central1:my-instance",
|
|
|
|
|
username="dbuser",
|
|
|
|
|
authType=GcpCloudsqlConfigurationSource(
|
|
|
|
|
password="dbpassword",
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
mysql_conn = _make_mysql_connection(connection)
|
|
|
|
|
mysql_conn._get_cloudsql_engine(connection)
|
|
|
|
|
|
|
|
|
|
mock_create_conn.assert_called_once()
|
|
|
|
|
call_kwargs = mock_create_conn.call_args
|
|
|
|
|
assert "creator" in call_kwargs.kwargs
|
|
|
|
|
|
|
|
|
|
creator_fn = call_kwargs.kwargs["creator"]
|
|
|
|
|
creator_fn()
|
|
|
|
|
|
|
|
|
|
mock_connector_inst.connect.assert_called_once()
|
|
|
|
|
connect_kwargs = mock_connector_inst.connect.call_args.kwargs
|
chore(ingestion): migrate to ruff for format + isort + unused-import (#27739)
* chore(ingestion): replace black/isort/pycln with ruff
- Swap formatter + import-sorter + unused-import tooling for ruff
(line-length 120, target py3.10) in ingestion + openmetadata-airflow-apis
- Drop dead [tool.mypy] config; basedpyright is the active type checker
- Bump requires-python to >=3.10 to match noxfile and CLAUDE.md (3.9 is
documented as broken on Mac in noxfile.py)
- Bump pre-commit-hooks v2.3 -> v5.0; the new check-json catches four
pre-existing JSON issues now excluded with an inline TODO
- Update Makefile py_format / py_format_check targets to call ruff
* chore(ingestion): grandfather ruff lint violations and apply ruff format
- 253 noqa markers added via 'ruff check --add-noqa' across 128 files,
freezing existing violations so this PR is a tooling-only swap. Per-rule
cleanup tracked in the TODO comment in ingestion/pyproject.toml.
- Bulk reformat from black 22.3 -> ruff format @ line-length 120.
Cosmetic only: imports balanced (-32/+32), structural keywords balanced
(-2221/+2221), no logic changes.
- Star-import rules (F403/F405) globally ignored; refactoring wildcard
imports across connectors is a separate effort.
* chore(ingestion): fix pylint findings surfaced after ruff format
- filters.py: drop redundant parens around re.match(...) in `if`
(C0325 superfluous-parens) — exposed when ruff format unwrapped them
- nosql_adaptor.py: move `# pylint: disable=unused-argument` from the
`column:` line to the `def` line so it covers `table` too (W0613) —
scope was line-based, lost when ruff split params onto multiple lines
- action1xx.py: replace `arguments-differ` with `signature-differs` in
the disable directive (was always wrong code) and drop the now-useless
`unused-argument` suppression (I0021)
* fix(ingestion): make ruff extend-exclude robust to multi-root invocations
CI's `make py_format_check` runs from the repo root and passes both
`ingestion/` and `./openmetadata-airflow-apis/` to ruff in a single
invocation. With multiple root paths, ruff's parallel file discovery
races on extend-exclude matching against the project root, so files
under `ingestion/src/metadata/generated/` were intermittently scanned
and produced ~830 I001 violations.
20-run repro: 10/20 fail without the fix, 20/20 pass with the fix.
Each excluded directory now appears twice in extend-exclude:
- the project-root-relative pattern (cwd = ingestion/)
- the prefixed pattern (cwd = repo root, multi-root invocation)
* chore(ingestion): address gitar-bot findings + cross-version pylint disable
- openmetadata-airflow-apis/pyproject.toml: switch coverage to module-name
source + [tool.coverage.paths] glob remap (matches the ingestion pattern).
Drops the hardcoded `env/lib/python3.9/site-packages/...` source path,
which broke after the requires-python bump to 3.10. (Finding 1)
- ingestion/setup.py: remove dead python_version<'3.9' / >='3.9' guards on
mysql-connector-python and testcontainers; promote locust to a regular
test dep (was conditionally added under sys.version_info >= (3, 9)). Also
remove the now-unused `import sys`. (Finding 3)
- ingestion/src/metadata/great_expectations/action1xx.py: cover both
arguments-differ (great_expectations 0.18.x parent) and signature-differs
(great_expectations 1.x parent) in the pylint disable comment, since
CI installs 0.18.x and local often has 1.x. unused-argument covers the
unused action_context. The opposite rule fires as I0021 useless-suppression
on each environment, which is informational and does not affect pylint's
exit code.
2026-04-27 08:05:28 +00:00
|
|
|
assert connect_kwargs["instance_connection_string"] == "my-project:us-central1:my-instance"
|
2026-04-06 04:56:06 +00:00
|
|
|
assert connect_kwargs["driver"] == "pymysql"
|
|
|
|
|
assert connect_kwargs["user"] == "dbuser"
|
|
|
|
|
assert connect_kwargs["password"] == "dbpassword"
|
|
|
|
|
assert "enable_iam_auth" not in connect_kwargs
|
|
|
|
|
|
chore(ingestion): migrate to ruff for format + isort + unused-import (#27739)
* chore(ingestion): replace black/isort/pycln with ruff
- Swap formatter + import-sorter + unused-import tooling for ruff
(line-length 120, target py3.10) in ingestion + openmetadata-airflow-apis
- Drop dead [tool.mypy] config; basedpyright is the active type checker
- Bump requires-python to >=3.10 to match noxfile and CLAUDE.md (3.9 is
documented as broken on Mac in noxfile.py)
- Bump pre-commit-hooks v2.3 -> v5.0; the new check-json catches four
pre-existing JSON issues now excluded with an inline TODO
- Update Makefile py_format / py_format_check targets to call ruff
* chore(ingestion): grandfather ruff lint violations and apply ruff format
- 253 noqa markers added via 'ruff check --add-noqa' across 128 files,
freezing existing violations so this PR is a tooling-only swap. Per-rule
cleanup tracked in the TODO comment in ingestion/pyproject.toml.
- Bulk reformat from black 22.3 -> ruff format @ line-length 120.
Cosmetic only: imports balanced (-32/+32), structural keywords balanced
(-2221/+2221), no logic changes.
- Star-import rules (F403/F405) globally ignored; refactoring wildcard
imports across connectors is a separate effort.
* chore(ingestion): fix pylint findings surfaced after ruff format
- filters.py: drop redundant parens around re.match(...) in `if`
(C0325 superfluous-parens) — exposed when ruff format unwrapped them
- nosql_adaptor.py: move `# pylint: disable=unused-argument` from the
`column:` line to the `def` line so it covers `table` too (W0613) —
scope was line-based, lost when ruff split params onto multiple lines
- action1xx.py: replace `arguments-differ` with `signature-differs` in
the disable directive (was always wrong code) and drop the now-useless
`unused-argument` suppression (I0021)
* fix(ingestion): make ruff extend-exclude robust to multi-root invocations
CI's `make py_format_check` runs from the repo root and passes both
`ingestion/` and `./openmetadata-airflow-apis/` to ruff in a single
invocation. With multiple root paths, ruff's parallel file discovery
races on extend-exclude matching against the project root, so files
under `ingestion/src/metadata/generated/` were intermittently scanned
and produced ~830 I001 violations.
20-run repro: 10/20 fail without the fix, 20/20 pass with the fix.
Each excluded directory now appears twice in extend-exclude:
- the project-root-relative pattern (cwd = ingestion/)
- the prefixed pattern (cwd = repo root, multi-root invocation)
* chore(ingestion): address gitar-bot findings + cross-version pylint disable
- openmetadata-airflow-apis/pyproject.toml: switch coverage to module-name
source + [tool.coverage.paths] glob remap (matches the ingestion pattern).
Drops the hardcoded `env/lib/python3.9/site-packages/...` source path,
which broke after the requires-python bump to 3.10. (Finding 1)
- ingestion/setup.py: remove dead python_version<'3.9' / >='3.9' guards on
mysql-connector-python and testcontainers; promote locust to a regular
test dep (was conditionally added under sys.version_info >= (3, 9)). Also
remove the now-unused `import sys`. (Finding 3)
- ingestion/src/metadata/great_expectations/action1xx.py: cover both
arguments-differ (great_expectations 0.18.x parent) and signature-differs
(great_expectations 1.x parent) in the pylint disable comment, since
CI installs 0.18.x and local often has 1.x. unused-argument covers the
unused action_context. The opposite rule fires as I0021 useless-suppression
on each environment, which is informational and does not affect pylint's
exit code.
2026-04-27 08:05:28 +00:00
|
|
|
@patch("metadata.ingestion.source.database.mysql.connection.create_generic_db_connection")
|
2026-04-06 04:56:06 +00:00
|
|
|
def test_cloudsql_iam_auth(self, mock_create_conn, mock_connector):
|
|
|
|
|
_, mock_connector_inst = mock_connector
|
|
|
|
|
mock_create_conn.return_value = MagicMock()
|
|
|
|
|
|
|
|
|
|
connection = MysqlConnection(
|
|
|
|
|
hostPort="my-project:us-central1:my-instance",
|
|
|
|
|
username="sa@my-project.iam",
|
|
|
|
|
authType=GcpCloudsqlConfigurationSource(
|
|
|
|
|
enableIamAuth=True,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
mysql_conn = _make_mysql_connection(connection)
|
|
|
|
|
mysql_conn._get_cloudsql_engine(connection)
|
|
|
|
|
|
|
|
|
|
creator_fn = mock_create_conn.call_args.kwargs["creator"]
|
|
|
|
|
creator_fn()
|
|
|
|
|
|
|
|
|
|
connect_kwargs = mock_connector_inst.connect.call_args.kwargs
|
|
|
|
|
assert connect_kwargs["enable_iam_auth"] is True
|
|
|
|
|
assert "password" not in connect_kwargs
|
|
|
|
|
|
chore(ingestion): migrate to ruff for format + isort + unused-import (#27739)
* chore(ingestion): replace black/isort/pycln with ruff
- Swap formatter + import-sorter + unused-import tooling for ruff
(line-length 120, target py3.10) in ingestion + openmetadata-airflow-apis
- Drop dead [tool.mypy] config; basedpyright is the active type checker
- Bump requires-python to >=3.10 to match noxfile and CLAUDE.md (3.9 is
documented as broken on Mac in noxfile.py)
- Bump pre-commit-hooks v2.3 -> v5.0; the new check-json catches four
pre-existing JSON issues now excluded with an inline TODO
- Update Makefile py_format / py_format_check targets to call ruff
* chore(ingestion): grandfather ruff lint violations and apply ruff format
- 253 noqa markers added via 'ruff check --add-noqa' across 128 files,
freezing existing violations so this PR is a tooling-only swap. Per-rule
cleanup tracked in the TODO comment in ingestion/pyproject.toml.
- Bulk reformat from black 22.3 -> ruff format @ line-length 120.
Cosmetic only: imports balanced (-32/+32), structural keywords balanced
(-2221/+2221), no logic changes.
- Star-import rules (F403/F405) globally ignored; refactoring wildcard
imports across connectors is a separate effort.
* chore(ingestion): fix pylint findings surfaced after ruff format
- filters.py: drop redundant parens around re.match(...) in `if`
(C0325 superfluous-parens) — exposed when ruff format unwrapped them
- nosql_adaptor.py: move `# pylint: disable=unused-argument` from the
`column:` line to the `def` line so it covers `table` too (W0613) —
scope was line-based, lost when ruff split params onto multiple lines
- action1xx.py: replace `arguments-differ` with `signature-differs` in
the disable directive (was always wrong code) and drop the now-useless
`unused-argument` suppression (I0021)
* fix(ingestion): make ruff extend-exclude robust to multi-root invocations
CI's `make py_format_check` runs from the repo root and passes both
`ingestion/` and `./openmetadata-airflow-apis/` to ruff in a single
invocation. With multiple root paths, ruff's parallel file discovery
races on extend-exclude matching against the project root, so files
under `ingestion/src/metadata/generated/` were intermittently scanned
and produced ~830 I001 violations.
20-run repro: 10/20 fail without the fix, 20/20 pass with the fix.
Each excluded directory now appears twice in extend-exclude:
- the project-root-relative pattern (cwd = ingestion/)
- the prefixed pattern (cwd = repo root, multi-root invocation)
* chore(ingestion): address gitar-bot findings + cross-version pylint disable
- openmetadata-airflow-apis/pyproject.toml: switch coverage to module-name
source + [tool.coverage.paths] glob remap (matches the ingestion pattern).
Drops the hardcoded `env/lib/python3.9/site-packages/...` source path,
which broke after the requires-python bump to 3.10. (Finding 1)
- ingestion/setup.py: remove dead python_version<'3.9' / >='3.9' guards on
mysql-connector-python and testcontainers; promote locust to a regular
test dep (was conditionally added under sys.version_info >= (3, 9)). Also
remove the now-unused `import sys`. (Finding 3)
- ingestion/src/metadata/great_expectations/action1xx.py: cover both
arguments-differ (great_expectations 0.18.x parent) and signature-differs
(great_expectations 1.x parent) in the pylint disable comment, since
CI installs 0.18.x and local often has 1.x. unused-argument covers the
unused action_context. The opposite rule fires as I0021 useless-suppression
on each environment, which is informational and does not affect pylint's
exit code.
2026-04-27 08:05:28 +00:00
|
|
|
@patch("metadata.ingestion.source.database.mysql.connection.create_generic_db_connection")
|
2026-04-06 04:56:06 +00:00
|
|
|
def test_cloudsql_url_is_bare_scheme(self, mock_create_conn, mock_connector):
|
|
|
|
|
mock_create_conn.return_value = MagicMock()
|
|
|
|
|
|
|
|
|
|
connection = MysqlConnection(
|
|
|
|
|
hostPort="my-project:us-central1:my-instance",
|
|
|
|
|
username="dbuser",
|
|
|
|
|
authType=GcpCloudsqlConfigurationSource(password="pw"),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
mysql_conn = _make_mysql_connection(connection)
|
|
|
|
|
mysql_conn._get_cloudsql_engine(connection)
|
|
|
|
|
|
|
|
|
|
url_fn = mock_create_conn.call_args.kwargs["get_connection_url_fn"]
|
|
|
|
|
assert url_fn(connection) == "mysql+pymysql://"
|
|
|
|
|
|
|
|
|
|
@patch("metadata.ingestion.source.database.mysql.connection.set_google_credentials")
|
chore(ingestion): migrate to ruff for format + isort + unused-import (#27739)
* chore(ingestion): replace black/isort/pycln with ruff
- Swap formatter + import-sorter + unused-import tooling for ruff
(line-length 120, target py3.10) in ingestion + openmetadata-airflow-apis
- Drop dead [tool.mypy] config; basedpyright is the active type checker
- Bump requires-python to >=3.10 to match noxfile and CLAUDE.md (3.9 is
documented as broken on Mac in noxfile.py)
- Bump pre-commit-hooks v2.3 -> v5.0; the new check-json catches four
pre-existing JSON issues now excluded with an inline TODO
- Update Makefile py_format / py_format_check targets to call ruff
* chore(ingestion): grandfather ruff lint violations and apply ruff format
- 253 noqa markers added via 'ruff check --add-noqa' across 128 files,
freezing existing violations so this PR is a tooling-only swap. Per-rule
cleanup tracked in the TODO comment in ingestion/pyproject.toml.
- Bulk reformat from black 22.3 -> ruff format @ line-length 120.
Cosmetic only: imports balanced (-32/+32), structural keywords balanced
(-2221/+2221), no logic changes.
- Star-import rules (F403/F405) globally ignored; refactoring wildcard
imports across connectors is a separate effort.
* chore(ingestion): fix pylint findings surfaced after ruff format
- filters.py: drop redundant parens around re.match(...) in `if`
(C0325 superfluous-parens) — exposed when ruff format unwrapped them
- nosql_adaptor.py: move `# pylint: disable=unused-argument` from the
`column:` line to the `def` line so it covers `table` too (W0613) —
scope was line-based, lost when ruff split params onto multiple lines
- action1xx.py: replace `arguments-differ` with `signature-differs` in
the disable directive (was always wrong code) and drop the now-useless
`unused-argument` suppression (I0021)
* fix(ingestion): make ruff extend-exclude robust to multi-root invocations
CI's `make py_format_check` runs from the repo root and passes both
`ingestion/` and `./openmetadata-airflow-apis/` to ruff in a single
invocation. With multiple root paths, ruff's parallel file discovery
races on extend-exclude matching against the project root, so files
under `ingestion/src/metadata/generated/` were intermittently scanned
and produced ~830 I001 violations.
20-run repro: 10/20 fail without the fix, 20/20 pass with the fix.
Each excluded directory now appears twice in extend-exclude:
- the project-root-relative pattern (cwd = ingestion/)
- the prefixed pattern (cwd = repo root, multi-root invocation)
* chore(ingestion): address gitar-bot findings + cross-version pylint disable
- openmetadata-airflow-apis/pyproject.toml: switch coverage to module-name
source + [tool.coverage.paths] glob remap (matches the ingestion pattern).
Drops the hardcoded `env/lib/python3.9/site-packages/...` source path,
which broke after the requires-python bump to 3.10. (Finding 1)
- ingestion/setup.py: remove dead python_version<'3.9' / >='3.9' guards on
mysql-connector-python and testcontainers; promote locust to a regular
test dep (was conditionally added under sys.version_info >= (3, 9)). Also
remove the now-unused `import sys`. (Finding 3)
- ingestion/src/metadata/great_expectations/action1xx.py: cover both
arguments-differ (great_expectations 0.18.x parent) and signature-differs
(great_expectations 1.x parent) in the pylint disable comment, since
CI installs 0.18.x and local often has 1.x. unused-argument covers the
unused action_context. The opposite rule fires as I0021 useless-suppression
on each environment, which is informational and does not affect pylint's
exit code.
2026-04-27 08:05:28 +00:00
|
|
|
@patch("metadata.ingestion.source.database.mysql.connection.create_generic_db_connection")
|
|
|
|
|
def test_cloudsql_sets_gcp_credentials_when_provided(self, mock_create_conn, mock_set_creds, mock_connector):
|
2026-04-06 04:56:06 +00:00
|
|
|
mock_create_conn.return_value = MagicMock()
|
|
|
|
|
|
|
|
|
|
gcp_config = MagicMock()
|
|
|
|
|
connection = MysqlConnection(
|
|
|
|
|
hostPort="my-project:us-central1:my-instance",
|
|
|
|
|
username="dbuser",
|
|
|
|
|
authType=GcpCloudsqlConfigurationSource(password="pw"),
|
|
|
|
|
)
|
|
|
|
|
connection.authType.gcpConfig = gcp_config
|
|
|
|
|
|
|
|
|
|
mysql_conn = _make_mysql_connection(connection)
|
|
|
|
|
mysql_conn._get_cloudsql_engine(connection)
|
|
|
|
|
|
|
|
|
|
mock_set_creds.assert_called_once_with(gcp_config)
|
|
|
|
|
|
|
|
|
|
@patch("metadata.ingestion.source.database.mysql.connection.set_google_credentials")
|
chore(ingestion): migrate to ruff for format + isort + unused-import (#27739)
* chore(ingestion): replace black/isort/pycln with ruff
- Swap formatter + import-sorter + unused-import tooling for ruff
(line-length 120, target py3.10) in ingestion + openmetadata-airflow-apis
- Drop dead [tool.mypy] config; basedpyright is the active type checker
- Bump requires-python to >=3.10 to match noxfile and CLAUDE.md (3.9 is
documented as broken on Mac in noxfile.py)
- Bump pre-commit-hooks v2.3 -> v5.0; the new check-json catches four
pre-existing JSON issues now excluded with an inline TODO
- Update Makefile py_format / py_format_check targets to call ruff
* chore(ingestion): grandfather ruff lint violations and apply ruff format
- 253 noqa markers added via 'ruff check --add-noqa' across 128 files,
freezing existing violations so this PR is a tooling-only swap. Per-rule
cleanup tracked in the TODO comment in ingestion/pyproject.toml.
- Bulk reformat from black 22.3 -> ruff format @ line-length 120.
Cosmetic only: imports balanced (-32/+32), structural keywords balanced
(-2221/+2221), no logic changes.
- Star-import rules (F403/F405) globally ignored; refactoring wildcard
imports across connectors is a separate effort.
* chore(ingestion): fix pylint findings surfaced after ruff format
- filters.py: drop redundant parens around re.match(...) in `if`
(C0325 superfluous-parens) — exposed when ruff format unwrapped them
- nosql_adaptor.py: move `# pylint: disable=unused-argument` from the
`column:` line to the `def` line so it covers `table` too (W0613) —
scope was line-based, lost when ruff split params onto multiple lines
- action1xx.py: replace `arguments-differ` with `signature-differs` in
the disable directive (was always wrong code) and drop the now-useless
`unused-argument` suppression (I0021)
* fix(ingestion): make ruff extend-exclude robust to multi-root invocations
CI's `make py_format_check` runs from the repo root and passes both
`ingestion/` and `./openmetadata-airflow-apis/` to ruff in a single
invocation. With multiple root paths, ruff's parallel file discovery
races on extend-exclude matching against the project root, so files
under `ingestion/src/metadata/generated/` were intermittently scanned
and produced ~830 I001 violations.
20-run repro: 10/20 fail without the fix, 20/20 pass with the fix.
Each excluded directory now appears twice in extend-exclude:
- the project-root-relative pattern (cwd = ingestion/)
- the prefixed pattern (cwd = repo root, multi-root invocation)
* chore(ingestion): address gitar-bot findings + cross-version pylint disable
- openmetadata-airflow-apis/pyproject.toml: switch coverage to module-name
source + [tool.coverage.paths] glob remap (matches the ingestion pattern).
Drops the hardcoded `env/lib/python3.9/site-packages/...` source path,
which broke after the requires-python bump to 3.10. (Finding 1)
- ingestion/setup.py: remove dead python_version<'3.9' / >='3.9' guards on
mysql-connector-python and testcontainers; promote locust to a regular
test dep (was conditionally added under sys.version_info >= (3, 9)). Also
remove the now-unused `import sys`. (Finding 3)
- ingestion/src/metadata/great_expectations/action1xx.py: cover both
arguments-differ (great_expectations 0.18.x parent) and signature-differs
(great_expectations 1.x parent) in the pylint disable comment, since
CI installs 0.18.x and local often has 1.x. unused-argument covers the
unused action_context. The opposite rule fires as I0021 useless-suppression
on each environment, which is informational and does not affect pylint's
exit code.
2026-04-27 08:05:28 +00:00
|
|
|
@patch("metadata.ingestion.source.database.mysql.connection.create_generic_db_connection")
|
|
|
|
|
def test_cloudsql_skips_gcp_credentials_when_not_provided(self, mock_create_conn, mock_set_creds, mock_connector):
|
2026-04-06 04:56:06 +00:00
|
|
|
mock_create_conn.return_value = MagicMock()
|
|
|
|
|
|
|
|
|
|
connection = MysqlConnection(
|
|
|
|
|
hostPort="my-project:us-central1:my-instance",
|
|
|
|
|
username="dbuser",
|
|
|
|
|
authType=GcpCloudsqlConfigurationSource(password="pw"),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
mysql_conn = _make_mysql_connection(connection)
|
|
|
|
|
mysql_conn._get_cloudsql_engine(connection)
|
|
|
|
|
|
|
|
|
|
mock_set_creds.assert_not_called()
|
|
|
|
|
|
chore(ingestion): migrate to ruff for format + isort + unused-import (#27739)
* chore(ingestion): replace black/isort/pycln with ruff
- Swap formatter + import-sorter + unused-import tooling for ruff
(line-length 120, target py3.10) in ingestion + openmetadata-airflow-apis
- Drop dead [tool.mypy] config; basedpyright is the active type checker
- Bump requires-python to >=3.10 to match noxfile and CLAUDE.md (3.9 is
documented as broken on Mac in noxfile.py)
- Bump pre-commit-hooks v2.3 -> v5.0; the new check-json catches four
pre-existing JSON issues now excluded with an inline TODO
- Update Makefile py_format / py_format_check targets to call ruff
* chore(ingestion): grandfather ruff lint violations and apply ruff format
- 253 noqa markers added via 'ruff check --add-noqa' across 128 files,
freezing existing violations so this PR is a tooling-only swap. Per-rule
cleanup tracked in the TODO comment in ingestion/pyproject.toml.
- Bulk reformat from black 22.3 -> ruff format @ line-length 120.
Cosmetic only: imports balanced (-32/+32), structural keywords balanced
(-2221/+2221), no logic changes.
- Star-import rules (F403/F405) globally ignored; refactoring wildcard
imports across connectors is a separate effort.
* chore(ingestion): fix pylint findings surfaced after ruff format
- filters.py: drop redundant parens around re.match(...) in `if`
(C0325 superfluous-parens) — exposed when ruff format unwrapped them
- nosql_adaptor.py: move `# pylint: disable=unused-argument` from the
`column:` line to the `def` line so it covers `table` too (W0613) —
scope was line-based, lost when ruff split params onto multiple lines
- action1xx.py: replace `arguments-differ` with `signature-differs` in
the disable directive (was always wrong code) and drop the now-useless
`unused-argument` suppression (I0021)
* fix(ingestion): make ruff extend-exclude robust to multi-root invocations
CI's `make py_format_check` runs from the repo root and passes both
`ingestion/` and `./openmetadata-airflow-apis/` to ruff in a single
invocation. With multiple root paths, ruff's parallel file discovery
races on extend-exclude matching against the project root, so files
under `ingestion/src/metadata/generated/` were intermittently scanned
and produced ~830 I001 violations.
20-run repro: 10/20 fail without the fix, 20/20 pass with the fix.
Each excluded directory now appears twice in extend-exclude:
- the project-root-relative pattern (cwd = ingestion/)
- the prefixed pattern (cwd = repo root, multi-root invocation)
* chore(ingestion): address gitar-bot findings + cross-version pylint disable
- openmetadata-airflow-apis/pyproject.toml: switch coverage to module-name
source + [tool.coverage.paths] glob remap (matches the ingestion pattern).
Drops the hardcoded `env/lib/python3.9/site-packages/...` source path,
which broke after the requires-python bump to 3.10. (Finding 1)
- ingestion/setup.py: remove dead python_version<'3.9' / >='3.9' guards on
mysql-connector-python and testcontainers; promote locust to a regular
test dep (was conditionally added under sys.version_info >= (3, 9)). Also
remove the now-unused `import sys`. (Finding 3)
- ingestion/src/metadata/great_expectations/action1xx.py: cover both
arguments-differ (great_expectations 0.18.x parent) and signature-differs
(great_expectations 1.x parent) in the pylint disable comment, since
CI installs 0.18.x and local often has 1.x. unused-argument covers the
unused action_context. The opposite rule fires as I0021 useless-suppression
on each environment, which is informational and does not affect pylint's
exit code.
2026-04-27 08:05:28 +00:00
|
|
|
@patch("metadata.ingestion.source.database.mysql.connection.create_generic_db_connection")
|
2026-04-06 04:56:06 +00:00
|
|
|
def test_cloudsql_passes_database_schema(self, mock_create_conn, mock_connector):
|
|
|
|
|
_, mock_connector_inst = mock_connector
|
|
|
|
|
mock_create_conn.return_value = MagicMock()
|
|
|
|
|
|
|
|
|
|
connection = MysqlConnection(
|
|
|
|
|
hostPort="my-project:us-central1:my-instance",
|
|
|
|
|
username="dbuser",
|
|
|
|
|
databaseSchema="mydb",
|
|
|
|
|
authType=GcpCloudsqlConfigurationSource(password="pw"),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
mysql_conn = _make_mysql_connection(connection)
|
|
|
|
|
mysql_conn._get_cloudsql_engine(connection)
|
|
|
|
|
|
|
|
|
|
creator_fn = mock_create_conn.call_args.kwargs["creator"]
|
|
|
|
|
creator_fn()
|
|
|
|
|
|
|
|
|
|
connect_kwargs = mock_connector_inst.connect.call_args.kwargs
|
|
|
|
|
assert connect_kwargs["db"] == "mydb"
|