Fix: Modernize for Python 3.12, Django 4.2+, and PostgreSQL 15+ Compatibility#39
Open
krupal-t2b wants to merge 5 commits into
Open
Fix: Modernize for Python 3.12, Django 4.2+, and PostgreSQL 15+ Compatibility#39krupal-t2b wants to merge 5 commits into
krupal-t2b wants to merge 5 commits into
Conversation
Updated Django and psycopg2 versions, added setuptools.
| from django.db import models | ||
| from django_prometheus.models import ExportModelOperationsMixin | ||
| from jsonfield import JSONField | ||
| from django.db.models import JSONField |
Comment on lines
+24
to
+26
| 'OPTIONS': { | ||
| 'options': '-c timezone=UTC', | ||
| }, |
Comment on lines
+25
to
+26
| 'options': '-c timezone=UTC', | ||
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR updates the backend to support modern deployment environments (Python 3.12, Django 4.2+, and PostgreSQL 15+). The current
masterbranch relies on Django 2.2 and outdated dependencies that completely fail to build or run on newer Ubuntu/Linux distributions.Key Issues Resolved
1. Python 3.12
distutilsMissing Errordistutilslibrary, causing the initialmanage.pycommands to crash.setuptoolstorequirements.txtto restore compatibility.2. Gunicorn 502 Bad Gateway (
jsonfielddeprecation)jsonfieldpackage tries to importugettext_lazyandforce_text, both of which were removed in Django 4.0+. This causes Gunicorn workers to silently fail on boot.jsonfielddependency entirely and swappedmodel/models.pyto use Django's nativedjango.db.models.JSONField.3. PostgreSQL 16 Timezone
AssertionErrorAssertionError: database connection isn't set to UTC.'OPTIONS': {'options': '-c timezone=UTC'}to theDATABASESconfiguration insettings.pyto force the connection to UTC.4. Django 4.0 URL Routing Crash
django.conf.urls.urlwas removed in Django 4.0, causing 500 errors on API endpoints.urls.pyimports to use the modern equivalent:from django.urls import re_path as url.5. Database Driver Build Failures
psycopg2fails to compile on modern Linux kernels without local C-compilers.requirements.txtto usepsycopg2-binaryfor pre-compiled wheel support.Testing
Successfully tested saving, loading, and listing charts on an Ubuntu 24.04 LTS instance running Python 3.12 and PostgreSQL 16 via Gunicorn and Nginx.