Skip to content

Trap Version Parsing Errors (ValueError on connect) #109

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

Open
jwp opened this issue Dec 3, 2020 · 8 comments
Open

Trap Version Parsing Errors (ValueError on connect) #109

jwp opened this issue Dec 3, 2020 · 8 comments
Labels

Comments

@jwp
Copy link
Contributor

jwp commented Dec 3, 2020

When connecting to servers that are not actually PostgreSQL, trap version parsing exceptions and issue a client warning instead.

Given the presence of a new server_version client parameter, use it instead of the version presented by the server averting the warning.

@jwp jwp added the v1.4 label Dec 10, 2020
@jwp jwp changed the title Trap Version Parsing Errors Trap Version Parsing Errors (ValueError on connect) Dec 10, 2020
@dtpryce
Copy link

dtpryce commented Dec 15, 2020

We have found this ValueError when connecting to older PostgreSQL instances also

@jwp
Copy link
Contributor Author

jwp commented Dec 15, 2020

It's only particular builds of PostgreSQL. Specifically, debian/ubuntu packages have chosen to modify the server_version issued to the client in a way that would (likely) break any driver/application that is splitting/parsing the string. This is inconsistent with the source releases made by postgresql.org and is not a modification that clients/applications can/would/should anticipate.

@jwp jwp pinned this issue Dec 15, 2020
@dtpryce
Copy link

dtpryce commented Dec 15, 2020

Yeah we are seeing this on an old postgres that has server version = 10.9 (Ubuntu 10.9-0ubuntu0.18.04.1)
If that helps you debug the issue.

I have a fix locally for that one module versionstring if you want it? Might not be too clever just an if statement to check the length of the expected version string.

@jwp
Copy link
Contributor Author

jwp commented Dec 15, 2020

I think they've released builds like this for some time. It is a known incompatibility.

The change that I will be committing regarding the issue will allow users to compensate by explicitly stating the server version. This is preferable as it allows for compensation of any variation, which is useful beyond one errant build.

@jpalladino84
Copy link

jpalladino84 commented May 25, 2021

Hi, I was just wondering if there was any movement on this? I am using the Postgres docker container and it is setting my PG_VERSION to PostgreSQL 13.3 (Debian 13.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit which is resulting in the versionstring.py error: invalid literal for int() with base 10: '3 (Debian 13.

I like your thoughts around passing in the version instead of trying to derive it and was wondering if there was an ETA or if I should attempt to patch this in for the time being?

@jwp
Copy link
Contributor Author

jwp commented May 27, 2021

My desire to implement this has stalled as the effect of the incompatibility has been present for so long. Either the driver has been patched locally already or it's not being used to connect to instances of those builds. Also, I'm not optimistic that a server version override is actually superior to runtime patching the version string parser. The latter being a solution that is already available to users.

@4thel00z
Copy link

4thel00z commented Jul 26, 2022

Can we have a sane default version in the cases where the version string cannot be parsed and a user warning ?
The way it is currently implemented it is simply unusable.

@awelzel
Copy link

awelzel commented Sep 21, 2022

Also, I'm not optimistic that a server version override is actually superior to runtime patching the version string parser. The latter being a solution that is already available to users.

Just ran into this using the postgres docker image from Docker hub: https://hub.docker.com/_/postgres

This is what I'm using as a runtime patch to work-around it:

import re

import postgresql
import postgresql.versionstring

# monkey patch postgresql.versionstring.split to accept 14.5 (Debian 14.5-1.pgdg110+1)

_orig_split = postgresql.versionstring.split

def _monkey_split(vstr):
    m = re.match("^([0-9]+\.[0-9]+[^\s]*)\s+\(.+\)$", vstr)
    if m is not None:
        vstr = m.group(1)
    return _orig_split(vstr)

postgresql.versionstring.split = _monkey_split

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants