You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "sehajsandhu123 (via GitHub)" <gi...@apache.org> on 2026/08/23 07:08:37 UTC

[PR] Allow keeping PostgresHook SQLAlchemy engines on psycopg2 [airflow]

sehajsandhu123 opened a new pull request, #72000:
URL: https://github.com/apache/airflow/pull/72000

   Provider 7.0.0 switched hook-built SQLAlchemy engines to psycopg (v3) whenever SQLAlchemy 2.x is installed, with no opt-out. The psycopg dialect renders typed bind casts, so string parameters PostgreSQL previously coerced implicitly now fail server-side — most visibly pandas.DataFrame.to_sql into uuid columns (#71977). Honor the existing DbApiHook sqlalchemy_scheme connection extra (and hook parameter) so connections that rely on psycopg2 behaviour can keep it.
   
    <!-- SPDX-License-Identifier: Apache-2.0
         https://www.apache.org/licenses/LICENSE-2.0 -->
   
   <!--
   Thank you for contributing!
   
   Please provide above a brief description of the changes made in this pull request.
   Write a good git commit message following this guide: https://chris.beams.io/posts/git-commit/
   
   Please make sure that your code changes are covered with tests.
   And in case of new features or big changes remember to adjust the documentation.
   
   For user-facing UI changes, please attach before/after screenshots (or a short
   screen recording) so reviewers can assess the visual impact.
   
   Feel free to ping (in general) for the review if you do not see reaction for a few days
   (72 Hours is the minimum reaction time you can expect from volunteers) - we sometimes miss notifications.
   
   In case of an existing issue, reference it using one of the following:
   
   * closes: #ISSUE
   * related: #ISSUE
   -->
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   <!--
   If generative AI tooling has been used in the process of authoring this PR, please
   change below checkbox to `[X]` followed by the name of the tool, uncomment the "Generated-by".
   -->
   
   - [ ] Yes (please specify the tool below)
   
   <!--
   Generated-by: [Tool Name] following [the guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   -->
   
   ---
   
   * Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
   * For fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
   * When adding dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   * For significant user-facing changes create newsfragment: `{pr_number}.significant.rst`, in [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments). You can add this file in a follow-up commit after the PR is created so you know the PR number.
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow keeping PostgresHook SQLAlchemy engines on psycopg2 [airflow]

Posted by "sehajsandhu123 (via GitHub)" <gi...@apache.org>.
sehajsandhu123 commented on PR #72000:
URL: https://github.com/apache/airflow/pull/72000#issuecomment-5425434971

   @Dev-iL Thanks for the review, I've added the requested regression test and upstream discussion links.
   
   I understand the caution, but this is an opt-in param, off by default. And it isn't really a new one — the convention already exists in the codebase: OdbcHook and MsSqlHook both support sqlalchemy_scheme for per-connection driver choice (pymssql vs pyodbc), and MySqlHook does the same through its client extra.
   
   Also, the 7.0.0 notes already give the metadata DB an explicit psycopg2 opt-out via sql_alchemy_conn — hook connections were the only part of this migration without one. Since it's off by default and the strict xfail will tell us when upstream makes it unnecessary, it should be easy to retire too.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow keeping PostgresHook SQLAlchemy engines on psycopg2 [airflow]

Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #72000:
URL: https://github.com/apache/airflow/pull/72000#issuecomment-5384767047

   Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our [Contributors' Guide](https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
   Here are some useful points:
   - Pay attention to the quality of your code (ruff, mypy and type annotations). Our [prek-hooks]( https://github.com/apache/airflow/blob/main/contributing-docs/08_static_code_checks.rst#prerequisites-for-prek-hooks) will help you with that.
   - In case of a new feature add useful documentation (in docstrings or in `docs/` directory). Adding a new operator? Check this short [guide](https://github.com/apache/airflow/blob/main/airflow-core/docs/howto/custom-operator.rst) Consider adding an example Dag that shows how users should use it.
   - Consider using [Breeze environment](https://github.com/apache/airflow/blob/main/dev/breeze/doc/README.rst) for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
   - Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
   - Please follow [ASF Code of Conduct](https://www.apache.org/foundation/policies/conduct) for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
   - Be sure to read the [Airflow Coding style]( https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#coding-style-and-best-practices).
   - Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
   Apache Airflow is a community-driven project and together we are making it better 🚀.
   In case of doubts contact the developers at:
   Mailing List: dev@airflow.apache.org
   Slack: https://s.apache.org/airflow-slack
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow keeping PostgresHook SQLAlchemy engines on psycopg2 [airflow]

Posted by "sehajsandhu123 (via GitHub)" <gi...@apache.org>.
sehajsandhu123 commented on code in PR #72000:
URL: https://github.com/apache/airflow/pull/72000#discussion_r3862441762


##########
providers/postgres/docs/changelog.rst:
##########
@@ -108,6 +108,9 @@ Breaking changes
     There is no connection or configuration option to keep hooks on psycopg2; the
     ``sql_alchemy_conn`` workarounds above cover the metadata database only. If your Dags rely on
     psycopg2-specific behaviour, test before upgrading or pin the provider below 7.0.0.
+    Starting with provider 7.1.0, the SQLAlchemy engines built by the hook can be kept on

Review Comment:
   @Dev-iL  yeah, I shouldn't have edited the changelog note.
   
   I've removed the 7.1.0 line now. The extra param is documented in connections/postgres.rst. whenever this actually ships, that release can mention it.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow keeping PostgresHook SQLAlchemy engines on psycopg2 [airflow]

Posted by "sehajsandhu123 (via GitHub)" <gi...@apache.org>.
sehajsandhu123 commented on code in PR #72000:
URL: https://github.com/apache/airflow/pull/72000#discussion_r3890466506


##########
providers/postgres/src/airflow/providers/postgres/hooks/postgres.py:
##########
@@ -192,7 +218,7 @@ def sqlalchemy_url(self) -> URL:
         if conn.extra_dejson.get("iam", False):
             conn.login, conn.password, conn.port = self.get_iam_token(conn)
         return URL.create(
-            drivername="postgresql+psycopg" if USE_PSYCOPG3 else "postgresql",
+            drivername=self.sqlalchemy_scheme,

Review Comment:
   @ashb  It's primarily a connection property, the hook param is just an override on top. The intended usage is setting it once on the connection (or not setting it at all is also fine, for backwards compatibility) and the hook param only kicks in if explicitly passed.
   
   The reason I added it is if most dags on a connection are fine on psycopg3 and only one or two break, it pins just those tasks instead of rolling the whole connection back to psycopg2. Keeps the opt-out small and lets the connection default move forward.
   
   Happy to drop the hook param if you just want the connection extra.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow keeping PostgresHook SQLAlchemy engines on psycopg2 [airflow]

Posted by "ashb (via GitHub)" <gi...@apache.org>.
ashb merged PR #72000:
URL: https://github.com/apache/airflow/pull/72000


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow keeping PostgresHook SQLAlchemy engines on psycopg2 [airflow]

Posted by "Dev-iL (via GitHub)" <gi...@apache.org>.
Dev-iL commented on code in PR #72000:
URL: https://github.com/apache/airflow/pull/72000#discussion_r3856153667


##########
providers/postgres/docs/changelog.rst:
##########
@@ -108,6 +108,9 @@ Breaking changes
     There is no connection or configuration option to keep hooks on psycopg2; the
     ``sql_alchemy_conn`` workarounds above cover the metadata database only. If your Dags rely on
     psycopg2-specific behaviour, test before upgrading or pin the provider below 7.0.0.
+    Starting with provider 7.1.0, the SQLAlchemy engines built by the hook can be kept on

Review Comment:
   @eladkal Do we have a placeholder for "next feature/bugfix version" for providers? One cannot know reliably in which release a feature might be included. 



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow keeping PostgresHook SQLAlchemy engines on psycopg2 [airflow]

Posted by "ashb (via GitHub)" <gi...@apache.org>.
ashb commented on code in PR #72000:
URL: https://github.com/apache/airflow/pull/72000#discussion_r3889372242


##########
providers/postgres/src/airflow/providers/postgres/hooks/postgres.py:
##########
@@ -192,7 +218,7 @@ def sqlalchemy_url(self) -> URL:
         if conn.extra_dejson.get("iam", False):
             conn.login, conn.password, conn.port = self.get_iam_token(conn)
         return URL.create(
-            drivername="postgresql+psycopg" if USE_PSYCOPG3 else "postgresql",
+            drivername=self.sqlalchemy_scheme,

Review Comment:
   I'm not sure if this should be an operator/hook parameter or something defined inside the Connection itself. 
   
   What was your thinking for putting it here?



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow keeping PostgresHook SQLAlchemy engines on psycopg2 [airflow]

Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #72000:
URL: https://github.com/apache/airflow/pull/72000#issuecomment-5776368151

   Awesome work, congrats on your first merged pull request! You are invited to check our [Issue Tracker](https://github.com/apache/airflow/issues) for additional contributions.
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org