Skip to content

incorrect PostgreSQL version, failed to connect to PG10/Debian #250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ldgeo opened this issue Jan 31, 2018 · 4 comments
Closed

incorrect PostgreSQL version, failed to connect to PG10/Debian #250

ldgeo opened this issue Jan 31, 2018 · 4 comments

Comments

@ldgeo
Copy link

ldgeo commented Jan 31, 2018

  • asyncpg version: 0.14.0
  • PostgreSQL version: 10.1
  • Python version: 3.6.4
  • Platform: Linux Debian sid
  • Do you use pgbouncer?: no
  • Did you install asyncpg with pip?: yes
  • If you built asyncpg locally, which version of Cython did you use?:
  • Can the issue be reproduced under both asyncio and
    uvloop?
    : not related to event loop

I experience an issue when trying to connect to my local postgresql cluster. The error is :

  File "/home/ludo/.virtualenvs/pyvt/lib/python3.6/site-packages/asyncpg/serverversion.py", line 49, in <listcomp>
    versions = [int(p) for p in parts][:3]
ValueError: invalid literal for int() with base 10: '1 (Debian 10'

PostgreSQL version given by the server itself :

[ludo@postgres] # select version();
                                                 version                                                 
---------------------------------------------------------------------------------------------------------
 PostgreSQL 10.1 (Debian 10.1-3) on x86_64-pc-linux-gnu, compiled by gcc (Debian 7.2.0-19) 7.2.0, 64-bit
(1 ligne)

PostgreSQL was installed from the main debian repositories :

apt-cache policy postgresql-10
postgresql-10:
  Installé : 10.1-3
  Candidat : 10.1-3
 Table de version :
 *** 10.1-3 500
        500 http://httpredir.debian.org/debian sid/main amd64 Packages
        100 /var/lib/dpkg/status

I looked into the code but failed to find where the version is fetched from PG.
The version_string received in the split_server_version_string function is equal to "10.1 (Debian 10.1-3)" but it should be only "10.1" according to the rest of the function.

Any ideas to fix it ?

elprans added a commit that referenced this issue Jan 31, 2018
Some distros (e.g Debian) like may inject their branding
into the numeric version string, so make sure to only look
at stuff before the first space.

Fixes: #250.
@elprans
Copy link
Member

elprans commented Jan 31, 2018

Sigh, arguably it's a Debian bug. There's no good reason why they should adulterate the PG_VERSION risking breakage like this. #251 has a workaround.

@ldgeo
Copy link
Author

ldgeo commented Jan 31, 2018

thanks for the quick fix.
For my understanding how do you retrieve the PG version ?

@elprans
Copy link
Member

elprans commented Jan 31, 2018

The version is reported by the server when the connection is established via a ParameterStatus protocol message.

elprans added a commit that referenced this issue Jan 31, 2018
Some distros (e.g Debian) like may inject their branding
into the numeric version string, so make sure to only look
at stuff before the first space.

Fixes: #250.
@jodal
Copy link

jodal commented Feb 14, 2018

It seems like this problem is now present in new/upgrades PostgreSQL databases on Heroku, so anyone running asyncpg on Heroku with a recent PostgreSQL version now needs to run asyncpg from master. It would be lovely to have a new release cut which includes this workaround.

Natrinicle added a commit to Natrinicle/asyncpg that referenced this issue Jun 25, 2021
MagicStack#250
MagicStack#261
MagicStack#771

Just tried to use this library through Ormar->Databases->AsyncPG against
a Yugabyte cluster and hit issue 771. Looks like this has been a problem
for a while now so going for a complete overhaul of the server version
extraction method. Using a groupdict regex against the version string
allows for much higher flexibility in extracting what we're looking for
and fixes 771 while not breaking any of the existing version patterns.
elprans pushed a commit that referenced this issue Aug 2, 2021
#250
#261
#771

Just tried to use this library through Ormar->Databases->AsyncPG against
a Yugabyte cluster and hit issue 771. Looks like this has been a problem
for a while now so going for a complete overhaul of the server version
extraction method. Using a groupdict regex against the version string
allows for much higher flexibility in extracting what we're looking for
and fixes #771 while not breaking any of the existing version patterns.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants