Skip to content
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

bug: Fix decimal.InvalidOperation on /system for some PG versions #3027

Merged
merged 1 commit into from
Mar 9, 2024

Conversation

richid
Copy link
Contributor

@richid richid commented Mar 7, 2024

Description

In #2730 the /system page was improved to warn the user if the version of Postgres they are using is out of date and should be updated. The current code attempts to determine the major versions by replacing 00 with . and then converting to a Decimal. Unfortunately, it appears the only value this method does not work for are initial releases of major versions, like 16.0.0.

For reference, either Postgres or the PsyCog driver represents the semver values but without the dots, so 16.0.0 becomes 1600000.

This change removes the string replace and Decimal conversion in favor of using the divmod() function. In this application it will return a tuple with the first element being the major version of Postgres. This is then used as before to compare against deprecated versions.

Versions

Postgres

=# SELECT version();
                                              version
------------------------------------------------------------------------------------------------------
PostgreSQL 16.0 (Debian 16.0-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
(1 row)

Tandoor

Tandoor (HEAD) - 1.5.14

commit a626bda1ab400efc2f6a5f9de3c307f857ea7026
Author: vabene1111 
Date:   Tue Mar 5 14:06:56 2024 +0100

    Merge branch 'develop'

Reproduction

>>> Decimal("160000".replace('00', '.'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
decimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>]
>>> Decimal("160001".replace('00', '.'))
Decimal('16.01')

Testing

Manually testing with the following values and confirmed the /system page displayed the info/warning/ok notices as expected.

postgres_ver = divmod(160000, 10000)[0]
postgres_ver = divmod(160001, 10000)[0]
postgres_ver = divmod(150000, 10000)[0]
postgres_ver = divmod(140000, 10000)[0]
postgres_ver = divmod(120000, 10000)[0]

@CLAassistant
Copy link

CLAassistant commented Mar 7, 2024

CLA assistant check
All committers have signed the CLA.

In TandoorRecipes#2730 the /system page was improved to warn the user if the version of Postgres they are using is out of date and should be updated. The current code attempts to determine the major versions by replacing `00` with `.` and then converting to a `Decimal`. Unfortunately, it appears the only value this method _does not_ work for are initial releases of major versions, like `16.0.0`.

For reference, either Postgres or the PsyCog driver represents the semver values but without the dots, so `16.0.0` becomes `1600000`.

This change removes the string replace and Decimal conversion in favor of using the divmod() function. In this application it will return a tuple with the first element being the major version of Postgres. This is then used as before to compare against deprecated versions.
@vabene1111
Copy link
Collaborator

awesome, thank you for fixing this!

@vabene1111 vabene1111 merged commit 2264050 into TandoorRecipes:develop Mar 9, 2024
1 check passed
@richid richid deleted the system-pg-version-fix branch March 11, 2024 15:12
@blknight88
Copy link

wondering if this caused a new issue as now I get a code 500 on the system page after updating to 1.5.15 and the "python3 version.py" now gets "fatal: no tag exactly matches" which worked before.

richid added a commit to richid/recipes that referenced this pull request Mar 23, 2024
…TandoorRecipes#3053]

The bug was a missing tuple index introduced in TandoorRecipes#3027. Added the index
and also wrapped everything in a try/catch to prevent future issues.
richid added a commit to richid/recipes that referenced this pull request Mar 23, 2024
…TandoorRecipes#3053]

The bug was a missing tuple index introduced in TandoorRecipes#3027. Added the index
and also wrapped everything in a try/catch to prevent future issues.
smilerz pushed a commit to smilerz/recipes that referenced this pull request Apr 11, 2024
…TandoorRecipes#3053]

The bug was a missing tuple index introduced in TandoorRecipes#3027. Added the index
and also wrapped everything in a try/catch to prevent future issues.
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

Successfully merging this pull request may close these issues.

None yet

4 participants