From 69af136122aaaa4495bf8731ca4ef076bf4a56bc Mon Sep 17 00:00:00 2001 From: Rich Schumacher Date: Thu, 7 Mar 2024 08:52:39 -0500 Subject: [PATCH] bug: Fix decimal.InvalidOperation on /system for some PG versions In https://github.com/TandoorRecipes/recipes/pull/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. --- cookbook/views/views.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cookbook/views/views.py b/cookbook/views/views.py index e3d057945f..f5f643291e 100644 --- a/cookbook/views/views.py +++ b/cookbook/views/views.py @@ -293,11 +293,10 @@ def system(request): if postgres: postgres_current = 16 # will need to be updated as PostgreSQL releases new major versions - from decimal import Decimal from django.db import connection - postgres_ver = Decimal(str(connection.pg_version).replace('00', '.')) + postgres_ver = divmod(connection.pg_version, 10000) if postgres_ver >= postgres_current: database_status = 'success' database_message = _('Everything is fine!')