SameerMesiah97 opened a new pull request, #66893: URL: https://github.com/apache/airflow/pull/66893
**Description** This change refactors psycopg-specific connection handling in `PostgresHook` and consolidates duplicated runtime test coverage shared between psycopg2 and psycopg3 implementations. Connection setup responsibilities previously embedded directly inside `get_conn` have been extracted into dedicated helper methods. `_get_cursor_config` now centralizes cursor configuration handling, while `_create_connection` encapsulates driver-specific connection initialization, including adapter registration and notice handler setup. The accompanying test suite has also been reorganized to reduce duplicated behavioral coverage. Shared runtime tests have been moved into `_BasePostgresHookRuntimeTests`, allowing psycopg2- and psycopg3-specific test classes to focus only on behavior that differs between implementations. **Rationale** `PostgresHook.get_conn` previously contained duplicated psycopg2- and psycopg3-specific connection setup logic. Maintaining separate inline code paths for cursor configuration, adapter registration, and notice handler initialization increases maintenance overhead and makes future changes harder to validate consistently across both drivers. Extracting `_get_cursor_config` and `_create_connection` simplifies the control flow in `get_conn`, reduces branching complexity, and makes psycopg-specific behavior easier to reason about and extend independently. The test suite had a similar issue, with substantial overlap between psycopg2 and psycopg3 runtime behavioral tests. Consolidating identical coverage into `_BasePostgresHookRuntimeTests` improves readability, reduces repeated CI execution for equivalent scenarios, and keeps implementation-specific tests scoped to behavior that actually differs. **Tests** * Consolidated duplicated runtime behavioral tests into `_BasePostgresHookRuntimeTests`. * Updated psycopg2 and psycopg3 runtime test classes to inherit shared coverage. * Preserved existing psycopg2-specific lineage, `execute_batch`, and notice handling tests. * Preserved existing psycopg3-specific `copy_expert` and notice handling coverage. * Updated and reorganized existing tests where appropriate. **Backwards Compatibility** This change only refactors test code and does not modify production behavior or public APIs. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
