Google: Guard bigquery_to_postgres's psycopg2-specific adapter registration#69493
Closed
Dev-iL wants to merge 1 commit into
Closed
Google: Guard bigquery_to_postgres's psycopg2-specific adapter registration#69493Dev-iL wants to merge 1 commit into
Dev-iL wants to merge 1 commit into
Conversation
register_adapter(list/dict, Json) is psycopg2-specific and previously ran unconditionally, forcing psycopg2 to be importable even when the resolved PostgresHook connection is on psycopg3 (a no-op there). Only import and call it when PostgresHook is actually on the psycopg2 path, so the module imports cleanly without psycopg2 installed. Note cross-branch dependency on the postgres provider's guard fix This guard only makes bigquery_to_postgres.py import cleanly without psycopg2 once apache-airflow-providers-postgres itself stops hard-requiring psycopg2 (a separate, independently-branched fix for the same migration). Document that dependency at the import site. Also fixes the absence-simulation test's finally block, which was reimporting the module while the fake absence was still monkeypatched, leaving it cached in a degraded state for the rest of the test session. Part of the migration tracked in apache#68453.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
related:
depends on:
register_adapter(list/dict, Json)inBigQueryToPostgresOperatoris psycopg2-specific and previously ran unconditionally, forcing psycopg2 to be importable even when the resolvedPostgresHookconnection is actually on psycopg3 (where it's a no-op). Only import and call it whenPostgresHookis actually on the psycopg2 path.What changed
providers/google/src/airflow/providers/google/cloud/transfers/bigquery_to_postgres.py: thefrom psycopg2.extensions import register_adapter/from psycopg2.extras import Jsonimports and theregister_adapter(...)calls are now conditional onnot PostgresHook.USE_PSYCOPG3, guarded insidepostgres_hook, with a comment documenting the dependency on the postgres provider's own guard fix.Test plan
bigquery_to_postgrestest suite passes.test_adapters_to_json_registered_on_psycopg2_path,test_adapters_not_registered_on_psycopg3_path,test_bigquery_to_postgres_module_imports_without_psycopg2(simulates psycopg2 absent viasys.modulespatching, confirms clean import).Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Sonnet 5) following the guidelines
{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.