question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Postgres connection URI incompatible with SQLAlchemy >= 1.4.0b1

See original GitHub issue

Apache Airflow version: 2.0.1 (possibly any?)

Kubernetes version (if you are using kubernetes) (use kubectl version): N/A

Environment: Any

  • Cloud provider or hardware configuration: Any
  • OS (e.g. from /etc/os-release): Any
  • Kernel (e.g. uname -a): Any
  • Install tools: Any
  • Others: Any

What happened:

From SQLAlchemy version 1.4.0b1, SQLAlchemy removed the support for the postgres prefix in URIs (used for example in create_engine), and now it supports only postgresql.

This affects all Airflow jobs that: (A) Use SQLAlchemy version >= 1.4.0 (B) Obtain/use a Postgres URI from the get_uri method of a PostgresHook (method defined in the DbApiHook - airflow/hooks/dbapi.py).

This is because the PostgresHook (airflow/providers/postgres/hooks/postgres.py) class, defines a class attribute conn_type = 'postgres' instead of postgresql.

Right now my airflow jobs with the updated SQLAlchemy that are using SQLAlchemy create_engine with a postgres db are broken.

What you expected to happen:

That Airflow jobs using SQLAlchemy >= 1.4.0 and SQLAlchemy’s create_engine with Postgres databases work correctly, and that get_uri generates a postgres URI starting with postgresql://.

Of course I could use an older SQLAlchemy version or manipulated the returned URI, but I guess it’d be nice if Airflow adapts to the updated prefix.

How to reproduce it:

Use the get_uri method of any PostgresHook.

Anything else we need to know:

N/A

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Giuzzillacommented, Apr 13, 2021

Duplicate to #14811.

I saw #14811 before opening this but I thought it might be worth it to open a separate issue as it’s a bit different, even if they are both caused by SQLAlchemy 1.4.

#14811 was fixed by pinning SQLAlchemy in Airflow requirements, but #14812 doesn’t help here. This is impacting jobs that are not sharing Airflow dependencies, e.g. custom docker images ran with the Kubernetes Pod Operator or Docker Operator, but which are relying on Airflow-generated URIs for connecting to postgresql.

1reaction
potiukcommented, Feb 7, 2022

Yep. confirmed (and it’s being voted now) . Thanks for pointing it out. Closed by #21205 indeed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python sqlalchemy error while creating engine object to ...
I am using sqlalchemy in python to connect to the database in PostgreSQL database but getting error. Can anyone please help me.
Read more >
1.4 Changelog — SQLAlchemy 2.0 Documentation
Made an adjustment to how the PostgreSQL dialect considers column types when it reflects columns from a table, to accommodate for alternative backends...
Read more >
Why is SQLAlchemy 1.4.x not connecting to Heroku Postgres?
When using SQLAlchemy 1.4.x to connect to Heroku Postgres, I receive the following ... SQLAlchemy 1.4.x has removed support for the postgres:// URI...
Read more >
apache-airflow-providers-postgres 5.3.1 - PyPI
The URIs returned by Postgres get_uri() returns postgresql:// instead of postgres:// prefix which is the only supported prefix for the SQLAlchemy 1.4.0+.
Read more >
sqlalchemy Changelog - pyup.io
narrower scale change was also made for the 1.4 series that adjusted the function label issue only. .. change:: :tags: change, postgresql, asyncpg...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found