Skip to content

Commit

Permalink
bug: Fix TypeError at /system due to invalid PostgreSQL values [Closes
Browse files Browse the repository at this point in the history
…#3053]

The bug was a missing tuple index introduced in #3027. Added the index
and also wrapped everything in a try/catch to prevent future issues.
  • Loading branch information
richid committed Mar 23, 2024
1 parent db310c4 commit 7957413
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions cookbook/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,16 +296,21 @@ def system(request):

from django.db import connection

postgres_ver = divmod(connection.pg_version, 10000)
if postgres_ver >= postgres_current:
database_status = 'success'
database_message = _('Everything is fine!')
elif postgres_ver < postgres_current - 2:
try:
postgres_ver = divmod(connection.pg_version, 10000)[0]
if postgres_ver >= postgres_current:
database_status = 'success'
database_message = _('Everything is fine!')
elif postgres_ver < postgres_current - 2:
database_status = 'danger'
database_message = _('PostgreSQL %(v)s is deprecated. Upgrade to a fully supported version!') % {'v': postgres_ver}
else:
database_status = 'info'
database_message = _('You are running PostgreSQL %(v1)s. PostgreSQL %(v2)s is recommended') % {'v1': postgres_ver, 'v2': postgres_current}
except Exception as e:
print(f"Error determining PostgreSQL version: {e}")
database_status = 'danger'
database_message = _('PostgreSQL %(v)s is deprecated. Upgrade to a fully supported version!') % {'v': postgres_ver}
else:
database_status = 'info'
database_message = _('You are running PostgreSQL %(v1)s. PostgreSQL %(v2)s is recommended') % {'v1': postgres_ver, 'v2': postgres_current}
database_message = _('Unable to determine PostgreSQL version.')
else:
database_status = 'info'
database_message = _(
Expand Down

0 comments on commit 7957413

Please sign in to comment.