Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Django 4.1 and remove compatibility code #183

Merged
merged 2 commits into from
Sep 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: '3.10'
mattseymour marked this conversation as resolved.
Show resolved Hide resolved

- name: Install dependencies
run: |
Expand Down
16 changes: 11 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ jobs:
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
django-version: ["3.2", "4.0"]
django-version: ["3.2", "4.0", "4.1"]
exclude:
# Python 3.6 is not compatible with 4.0
- python-version: 3.6
django-version: 4.0
- python-version: "3.6"
django-version: "4.0"
# Python 3.6 is not compatible with 4.1
- python-version: "3.6"
django-version: "4.1"
# Python 3.7 is not compatible with 4.0
- python-version: 3.7
django-version: 4.0
- python-version: "3.7"
django-version: "4.0"
# Python 3.7 is not compatible with 4.1
- python-version: "3.7"
django-version: "4.1"
fail-fast: false
steps:
- uses: actions/checkout@v3
Expand Down
21 changes: 3 additions & 18 deletions dj_database_url.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
# -*- coding: utf-8 -*-

import os
import urllib.parse as urlparse

try:
from django import VERSION as DJANGO_VERSION
except ImportError:
DJANGO_VERSION = None


# Register database schemes in URLs.
urlparse.uses_netloc.append("postgres")
urlparse.uses_netloc.append("postgresql")
Expand All @@ -32,6 +24,9 @@
DEFAULT_ENV = "DATABASE_URL"

SCHEMES = {
"postgres": "django.db.backends.postgresql",
"postgresql": "django.db.backends.postgresql",
"pgsql": "django.db.backends.postgresql",
"postgis": "django.contrib.gis.db.backends.postgis",
"mysql": "django.db.backends.mysql",
"mysql2": "django.db.backends.mysql",
Expand All @@ -49,16 +44,6 @@
"timescalegis": "timescale.db.backends.postgis",
}

# https://docs.djangoproject.com/en/2.0/releases/2.0/#id1
if DJANGO_VERSION and DJANGO_VERSION < (2, 0):
SCHEMES["postgres"] = "django.db.backends.postgresql_psycopg2"
SCHEMES["postgresql"] = "django.db.backends.postgresql_psycopg2"
SCHEMES["pgsql"] = "django.db.backends.postgresql_psycopg2"
else:
SCHEMES["postgres"] = "django.db.backends.postgresql"
SCHEMES["postgresql"] = "django.db.backends.postgresql"
SCHEMES["pgsql"] = "django.db.backends.postgresql"
Comment on lines -52 to -60
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Django 2.0 is long past supported so this compatibility branch can go



def config(
env=DEFAULT_ENV, default=None, engine=None, conn_max_age=0, ssl_require=False
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
Copy link
Contributor Author

Choose a reason for hiding this comment

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

removing Python 2 compat comment

from setuptools import setup

with open("README.rst") as readme_rst:
Expand All @@ -14,7 +13,7 @@
long_description=readme,
long_description_content_type="text/x-rst",
py_modules=["dj_database_url"],
install_requires=["Django>3.2"],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

looks like this was accidentally blocking install on still-supported Django 3.2 since #162

install_requires=["Django>=3.2"],
zip_safe=False,
include_package_data=True,
platforms="any",
Expand All @@ -29,6 +28,7 @@
"Framework :: Django",
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.0",
"Framework :: Django :: 4.1",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
Expand Down
27 changes: 8 additions & 19 deletions test_dj_database_url.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
import os
import unittest

try:
from django import VERSION as DJANGO_VERSION
except ImportError:
DJANGO_VERSION = None

import dj_database_url

POSTGIS_URL = "postgis://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn"

# Django deprecated the `django.db.backends.postgresql_psycopg2` in 2.0.
# https://docs.djangoproject.com/en/2.0/releases/2.0/#id1
EXPECTED_POSTGRES_ENGINE = "django.db.backends.postgresql"
if DJANGO_VERSION and DJANGO_VERSION < (2, 0):
EXPECTED_POSTGRES_ENGINE = "django.db.backends.postgresql_psycopg2"
Comment on lines -13 to -17
Copy link
Contributor Author

Choose a reason for hiding this comment

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

removing test variance from old compat code



class DatabaseTestSuite(unittest.TestCase):
def test_postgres_parsing(self):
url = "postgres://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn"
url = dj_database_url.parse(url)

assert url["ENGINE"] == EXPECTED_POSTGRES_ENGINE
assert url["ENGINE"] == "django.db.backends.postgresql"
assert url["NAME"] == "d8r82722r2kuvn"
assert url["HOST"] == "ec2-107-21-253-135.compute-1.amazonaws.com"
assert url["USER"] == "uf07k1i6d8ia0v"
Expand All @@ -33,7 +22,7 @@ def test_postgres_unix_socket_parsing(self):
url = "postgres://%2Fvar%2Frun%2Fpostgresql/d8r82722r2kuvn"
url = dj_database_url.parse(url)

assert url["ENGINE"] == EXPECTED_POSTGRES_ENGINE
assert url["ENGINE"] == "django.db.backends.postgresql"
assert url["NAME"] == "d8r82722r2kuvn"
assert url["HOST"] == "/var/run/postgresql"
assert url["USER"] == ""
Expand All @@ -43,7 +32,7 @@ def test_postgres_unix_socket_parsing(self):
url = "postgres://%2FUsers%2Fpostgres%2FRuN/d8r82722r2kuvn"
url = dj_database_url.parse(url)

assert url["ENGINE"] == EXPECTED_POSTGRES_ENGINE
assert url["ENGINE"] == "django.db.backends.postgresql"
assert url["HOST"] == "/Users/postgres/RuN"
assert url["USER"] == ""
assert url["PASSWORD"] == ""
Expand All @@ -53,7 +42,7 @@ def test_ipv6_parsing(self):
url = "postgres://ieRaekei9wilaim7:wegauwhgeuioweg@[2001:db8:1234::1234:5678:90af]:5431/d8r82722r2kuvn"
url = dj_database_url.parse(url)

assert url["ENGINE"] == EXPECTED_POSTGRES_ENGINE
assert url["ENGINE"] == "django.db.backends.postgresql"
assert url["NAME"] == "d8r82722r2kuvn"
assert url["HOST"] == "2001:db8:1234::1234:5678:90af"
assert url["USER"] == "ieRaekei9wilaim7"
Expand All @@ -63,7 +52,7 @@ def test_ipv6_parsing(self):
def test_postgres_search_path_parsing(self):
url = "postgres://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn?currentSchema=otherschema"
url = dj_database_url.parse(url)
assert url["ENGINE"] == EXPECTED_POSTGRES_ENGINE
assert url["ENGINE"] == "django.db.backends.postgresql"
assert url["NAME"] == "d8r82722r2kuvn"
assert url["HOST"] == "ec2-107-21-253-135.compute-1.amazonaws.com"
assert url["USER"] == "uf07k1i6d8ia0v"
Expand All @@ -76,7 +65,7 @@ def test_postgres_parsing_with_special_characters(self):
url = "postgres://%23user:%23password@ec2-107-21-253-135.compute-1.amazonaws.com:5431/%23database"
url = dj_database_url.parse(url)

assert url["ENGINE"] == EXPECTED_POSTGRES_ENGINE
assert url["ENGINE"] == "django.db.backends.postgresql"
assert url["NAME"] == "#database"
assert url["HOST"] == "ec2-107-21-253-135.compute-1.amazonaws.com"
assert url["USER"] == "#user"
Expand Down Expand Up @@ -150,7 +139,7 @@ def test_database_url(self):

url = dj_database_url.config()

assert url["ENGINE"] == EXPECTED_POSTGRES_ENGINE
assert url["ENGINE"] == "django.db.backends.postgresql"
assert url["NAME"] == "d8r82722r2kuvn"
assert url["HOST"] == "ec2-107-21-253-135.compute-1.amazonaws.com"
assert url["USER"] == "uf07k1i6d8ia0v"
Expand Down Expand Up @@ -210,7 +199,7 @@ def test_database_url_with_options(self):
] = "postgres://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn?sslrootcert=rds-combined-ca-bundle.pem&sslmode=verify-full"
url = dj_database_url.config()

assert url["ENGINE"] == EXPECTED_POSTGRES_ENGINE
assert url["ENGINE"] == "django.db.backends.postgresql"
assert url["NAME"] == "d8r82722r2kuvn"
assert url["HOST"] == "ec2-107-21-253-135.compute-1.amazonaws.com"
assert url["USER"] == "uf07k1i6d8ia0v"
Expand Down