Skip to content

Commit

Permalink
Merge pull request #3059 from richid/fix-system-issue-3503
Browse files Browse the repository at this point in the history
bug: Fix TypeError at /system due to invalid PostgreSQL values [Closes #3053]
  • Loading branch information
vabene1111 committed Mar 25, 2024
2 parents 87327b0 + 7957413 commit 57304f9
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 57304f9

Please sign in to comment.