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

[PR] Make SQLAlchemy optional for Postgres provider [airflow]

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

   This PR makes SQLAlchemy an optional dependency for the Postgres provider, following the same pattern already applied to other providers (for example Presto and Exasol).
   
   ### Summary of changes
   - Removed hard SQLAlchemy imports from module level
   - Imported SQLAlchemy lazily inside methods that require it
   - Raised `AirflowOptionalProviderFeatureException` when SQLAlchemy-dependent functionality is used without SQLAlchemy installed
   - Kept SQLAlchemy as an optional extra dependency
   
   This aligns the Postgres provider with the guidance described in the parent issue.
   
   ### Note
   Apologies for any confusion earlier — I had to delete the previous PR due to some local issues and have opened this new PR with the corrected and final changes.
   
   ### References
   - Related to: #59905
   - Parent issue: #59895
   


-- 
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] Make SQLAlchemy optional for Postgres provider [airflow]

Posted by "Prab-27 (via GitHub)" <gi...@apache.org>.
Prab-27 commented on code in PR #60236:
URL: https://github.com/apache/airflow/pull/60236#discussion_r2671554071


##########
providers/postgres/pyproject.toml:
##########


Review Comment:
   @potiuk do we need to add just dependency without min version constraint ? (since min version already defined in optional dependency) 
   like : [here](https://github.com/apache/airflow/pull/60062#discussion_r2665516753)



-- 
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] Make SQLAlchemy optional for Postgres provider [airflow]

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


##########
providers/postgres/src/airflow/providers/postgres/hooks/postgres.py:
##########
@@ -166,7 +165,14 @@ def __cast_nullable(value, dst_type: type) -> Any:
         return dst_type(value) if value is not None else None
 
     @property
-    def sqlalchemy_url(self) -> URL:
+    def sqlalchemy_url(self):

Review Comment:
   Thanks for the suggestion — I’ve restored the -> URL return type and added the import under TYPE_CHECKING so it doesn’t introduce a runtime dependency. @potiuk @justinpakzad 



-- 
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] Make SQLAlchemy optional for Postgres provider [airflow]

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

   Hi @justinpazkad @potiuk , I’m currently seeing a CI failure from a pre-commit hook related to imports in postgres.py.
   I’m not fully sure whether the preferred approach here is to remove one of the imports, adjust the TYPE_CHECKING usage, or use an alternative pattern.
   Could you please suggest the recommended way to handle this? Thanks!


-- 
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] Make SQLAlchemy optional for Postgres provider [airflow]

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


##########
providers/postgres/src/airflow/providers/postgres/hooks/postgres.py:
##########
@@ -166,7 +165,14 @@ def __cast_nullable(value, dst_type: type) -> Any:
         return dst_type(value) if value is not None else None
 
     @property
-    def sqlalchemy_url(self) -> URL:
+    def sqlalchemy_url(self):

Review Comment:
   Yep



-- 
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] Make SQLAlchemy optional for Postgres provider [airflow]

Posted by "mohit7705 (via GitHub)" <gi...@apache.org>.
mohit7705 closed pull request #60236: Make SQLAlchemy optional for Postgres provider
URL: https://github.com/apache/airflow/pull/60236


-- 
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] Make SQLAlchemy optional for Postgres provider [airflow]

Posted by "Prab-27 (via GitHub)" <gi...@apache.org>.
Prab-27 commented on code in PR #60236:
URL: https://github.com/apache/airflow/pull/60236#discussion_r2671538098


##########
providers/postgres/pyproject.toml:
##########


Review Comment:
   We need to add dependency here  : related discussion : [here](https://github.com/apache/airflow/pull/60062#discussion_r2665512748)



-- 
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] Make SQLAlchemy optional for Postgres provider [airflow]

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

   hi @potiuk
   can you pls review this ,
   tell me if any correction  needed .


-- 
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] Make SQLAlchemy optional for Postgres provider [airflow]

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

   You need to install `prek `hook and run `prek run --all-files` .this will automatically fix the static checks 
   


-- 
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] Make SQLAlchemy optional for Postgres provider [airflow]

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


##########
providers/postgres/src/airflow/providers/postgres/hooks/postgres.py:
##########
@@ -166,7 +165,14 @@ def __cast_nullable(value, dst_type: type) -> Any:
         return dst_type(value) if value is not None else None
 
     @property
-    def sqlalchemy_url(self) -> URL:
+    def sqlalchemy_url(self):

Review Comment:
   I think you should still include the return type here: `-> URL`. You can add the import under the `if TYPE_CHECKING` condition. 



-- 
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