Fixes #29358: fix BigQuery test connection signature, per-project scoping, and engine teardown#29359
Conversation
96c0483 to
11a8650
Compare
…ping, and engine teardown
11a8650 to
40a98b6
Compare
|
|
Code Review ✅ Approved 1 resolved / 1 findingsRestores BigQuery test connection functionality by fixing the call signature, enabling per-project scoping, and ensuring proper engine disposal. No issues found after verifying with new mutation-checked regression tests. ✅ 1 resolved✅ Quality: Test asserts internal call signature via mocked internal fns
OptionsDisplay: compact → Showing less information. Comment with these commands to change:
Was this helpful? React with 👍 / 👎 | Gitar |



Fixes #29358
What
Follow-up to the
BaseConnectionmigration (#28977). The BigQuery test connection crashed withTypeError: 'BigQueryConnection' object cannot be interpreted as an integer, lost per-project testing, and leaked the test-connection engine.How
BigquerySource._test_connection: call the test function with the migrated signature (metadataonly) — the old(metadata, engine, service_connection)call pushed the service connection intotimeout_seconds, which reachedsignal.alarm(). Restore per-project testing by scoping the service connection to each project.helper.py: extractclone_connection_for_project(thedeepcopy+SingleProjectIdscope), reused byget_inspector_details.BigQueryConnection: registerengine.disposevia_on_closein_get_client, and wraptest_connectionintry/finally: self.close()so each per-project engine is disposed.Tests
New
test_bigquery_test_connection.py(3 tests):_test_connectioninvokes the test function once per project withmetadataonly (guards the crash signature);test_connectiondisposes its engine (guards both the_on_closeregistration and thefinally: self.close()).Mutation-checked (reverting each fix fails the matching test); ruff clean.
Greptile Summary
This PR fixes three bugs introduced by the
BaseConnectionmigration (#28977) in the BigQuery connector: aTypeErrorcrash whentest_connectionwas called with the old three-argument signature (service connection object fell intotimeout_seconds), lost per-project scoping during test connection, and an engine leak after each test run.connection.py: registersengine.disposevia_on_closein_get_clientand addstry/finally: self.close()totest_connectionso the engine is always released.helper.py: extractsclone_connection_for_project(deep-copy +SingleProjectIdscope) and reuses it in bothget_inspector_detailsand the metadata source, eliminating the duplicated deepcopy+assignment pattern.metadata.py: fixes_test_connectionto calltest_connection_fn(self.metadata)with the new single-argument signature and scopes each call to its own project viaclone_connection_for_project.Confidence Score: 5/5
Safe to merge — all three targeted bugs are fixed with correct logic and each fix is covered by a dedicated regression test.
The changes are narrow and well-scoped: a two-line engine teardown addition in connection.py, a clean refactor that extracts an existing deepcopy pattern in helper.py, and a one-liner signature correction in metadata.py. BaseConnection.close() uses ExitStack with a full reset, so there is no risk of double-disposal or stale callback accumulation. The three new unit tests are mutation-checked and directly guard against regression of the exact bugs being fixed.
No files require special attention.
Important Files Changed
Sequence Diagram
%%{init: {'theme': 'neutral'}}%% sequenceDiagram participant MS as BigquerySource._test_connection participant H as helper.clone_connection_for_project participant SC as get_test_connection_fn participant BC as BigQueryConnection.test_connection participant GC as _get_client participant ES as ExitStack (_on_close) participant E as SQLAlchemy Engine loop for each project_id MS->>H: deepcopy(service_connection) + SingleProjectId(project_id) H-->>MS: project_connection (scoped) MS->>SC: get_test_connection_fn(project_connection) SC-->>MS: bound test_connection_fn MS->>BC: test_connection_fn(metadata) BC->>GC: self.client (lazy build) GC->>E: create_generic_db_connection(...) GC->>ES: _on_close(engine.dispose) GC-->>BC: engine BC->>BC: test_connection_inner(engine) Note over BC: try/finally BC->>ES: self.close() ES->>E: engine.dispose() ES->>ES: "reset ExitStack, _client=None" end%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%% sequenceDiagram participant MS as BigquerySource._test_connection participant H as helper.clone_connection_for_project participant SC as get_test_connection_fn participant BC as BigQueryConnection.test_connection participant GC as _get_client participant ES as ExitStack (_on_close) participant E as SQLAlchemy Engine loop for each project_id MS->>H: deepcopy(service_connection) + SingleProjectId(project_id) H-->>MS: project_connection (scoped) MS->>SC: get_test_connection_fn(project_connection) SC-->>MS: bound test_connection_fn MS->>BC: test_connection_fn(metadata) BC->>GC: self.client (lazy build) GC->>E: create_generic_db_connection(...) GC->>ES: _on_close(engine.dispose) GC-->>BC: engine BC->>BC: test_connection_inner(engine) Note over BC: try/finally BC->>ES: self.close() ES->>E: engine.dispose() ES->>ES: "reset ExitStack, _client=None" endReviews (10): Last reviewed commit: "Merge branch 'main' into ices2/bigquery-..." | Re-trigger Greptile