Skip to content

Fix: Modernize for Python 3.12, Django 4.2+, and PostgreSQL 15+ Compatibility#39

Open
krupal-t2b wants to merge 5 commits into
tradingview:masterfrom
krupal-t2b:master
Open

Fix: Modernize for Python 3.12, Django 4.2+, and PostgreSQL 15+ Compatibility#39
krupal-t2b wants to merge 5 commits into
tradingview:masterfrom
krupal-t2b:master

Conversation

@krupal-t2b

Copy link
Copy Markdown

Overview

This PR updates the backend to support modern deployment environments (Python 3.12, Django 4.2+, and PostgreSQL 15+). The current master branch 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 distutils Missing Error

  • Issue: Python 3.12 removed the standard distutils library, causing the initial manage.py commands to crash.
  • Fix: Added setuptools to requirements.txt to restore compatibility.

2. Gunicorn 502 Bad Gateway (jsonfield deprecation)

  • Issue: The external jsonfield package tries to import ugettext_lazy and force_text, both of which were removed in Django 4.0+. This causes Gunicorn workers to silently fail on boot.
  • Fix: Removed the jsonfield dependency entirely and swapped model/models.py to use Django's native django.db.models.JSONField.

3. PostgreSQL 16 Timezone AssertionError

  • Issue: Modern PostgreSQL drivers strictly enforce timezone awareness. Retrieving a saved chart throws AssertionError: database connection isn't set to UTC.
  • Fix: Added 'OPTIONS': {'options': '-c timezone=UTC'} to the DATABASES configuration in settings.py to force the connection to UTC.

4. Django 4.0 URL Routing Crash

  • Issue: django.conf.urls.url was removed in Django 4.0, causing 500 errors on API endpoints.
  • Fix: Updated all urls.py imports to use the modern equivalent: from django.urls import re_path as url.

5. Database Driver Build Failures

  • Issue: psycopg2 fails to compile on modern Linux kernels without local C-compilers.
  • Fix: Swapped requirements.txt to use psycopg2-binary for 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.

@romfrancois romfrancois requested a review from Copilot May 15, 2026 07:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.

Comment thread model/models.py
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',
},
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.

2 participants