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

Add in support for Django 5.0 by adding in compat functionality for datetime_safe #1666

Merged
merged 37 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
2007d87
Update to support Django 4.1
chander Sep 15, 2022
5bfff6c
Merge branch 'django-tastypie:master' into master
chander Sep 15, 2022
8123360
Update authors
chander Sep 15, 2022
47f8058
Update tox.ini to add django 4.1
chander Sep 16, 2022
0c6bd4a
Add Django 4.1 to the workflows
chander Sep 16, 2022
e0da56a
Add in Django 4.1 support to the readme
chander Sep 16, 2022
3b7a291
Re-add in 4.0 for completeness
chander Sep 16, 2022
6786505
Remove Python 3.7 from the docs test for
chander Sep 16, 2022
7f8a990
Update the cookbook.rst file to store the inlines as a list consistently
chander Sep 16, 2022
98a9b24
Django removed the _sanitize_token function (which returned a new tok…
chander Sep 16, 2022
3b8eec9
Several other changes to support Django 4.1
chander Sep 16, 2022
74da197
Address flake errors
chander Sep 16, 2022
6deca24
fix flake error
chander Sep 16, 2022
784718c
update to use a new check_token_format function from compat.py
chander Oct 5, 2022
e84606a
Flake issues addressed..
chander Oct 5, 2022
436277f
Fix the flake error - my flake formatter adds two blank lines after a…
chander Oct 5, 2022
ee15e58
missed on reference to the old way of doing things
chander Oct 5, 2022
4063cb7
fix the import of the check_token_format function
chander Oct 5, 2022
109d06f
Be more deliberate with the import based on the version of Django in …
chander Oct 5, 2022
fc22f98
Same import issue
chander Oct 5, 2022
0d16e1b
updates to tastypie to add in support for django 5.0
chander Jan 9, 2024
e5d77da
Remove extra blank lines to pass old flake
chander Jan 9, 2024
5fc7ce4
switch the docs so we don't have a version issue
chander Jan 9, 2024
c2c310b
exclude python 3.6 for django 5
chander Jan 9, 2024
b9a0447
fix an oopsie - datetime is a packge, not a function - same with date…
chander Jan 9, 2024
01fabd0
ignore flake for unused error
chander Jan 9, 2024
33c3f41
Remove CryptPasswordHasher for django versions greater than 4.2
chander Jan 9, 2024
1f017d5
Fix for docs
chander Jan 9, 2024
7c68d1f
remove 3.9/django 5 combo
chander Jan 9, 2024
a9bd88d
use list, not tuple
chander Jan 9, 2024
c8d9859
Refactor code to properly use datetime.timezone.utc rather than the d…
chander Jan 9, 2024
960cb52
Revert "Refactor code to properly use datetime.timezone.utc rather th…
chander Jan 9, 2024
2829a92
add in compat functionality to monkey-patch timezone to have a utc at…
chander Jan 9, 2024
a0348d8
Fix flake issues
chander Jan 9, 2024
7c70497
update authors
chander Jan 9, 2024
af5c6da
fix doc builds
chander Jan 9, 2024
e213f6d
change >= to > for correctness
chander Jan 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
fail-fast: false
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]
django-version: ["3.2", "4.0", "4.1", "4.2"] # Todo: add "dev" back
django-version: ["3.2", "4.0", "4.1", "4.2", "5.0"] # Todo: add "dev" back
exclude:
- python-version: "3.6"
django-version: "4.0"
Expand All @@ -30,6 +30,14 @@ jobs:
django-version: "4.2"
- python-version: "3.7"
django-version: "4.2"
- python-version: "3.6"
django-version: "5.0"
- python-version: "3.7"
django-version: "5.0"
- python-version: "3.8"
django-version: "5.0"
- python-version: "3.9"
django-version: "5.0"
# - python-version: "3.6"
# django-version: "dev"
# - python-version: "3.7"
Expand Down
2 changes: 1 addition & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Contributors:
* Matt Briançon (mattbriancon) for various patches
* Blayze Wilhelm (blayzen-w) for a small patch that fixed an issue with saving (PR #1628)
* Ryan Young (ryanneilyoung) for removing python 2 code
* Chander Ganesan (chander) for minor patches
* Chander Ganesan (chander) for minor patches, added support for django 4.1 and 5.0


Thanks to Tav for providing validate_jsonp.py, placed in public domain.
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Core
----

* Python 3.6+, preferably 3.8+ (Whatever is supported by your version of Django)
* Django 4.2, 3.2 (LTS releases), or Django 4.0 / 4.1 (intermediate releases)
* Django 4.2, 3.2 (LTS releases), or Django 4.0, 4.1, and 5.0 (intermediate releases)
* dateutil (http://labix.org/python-dateutil) >= 2.1

Format Support
Expand Down
2 changes: 1 addition & 1 deletion docs/cookbook.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ modifying ``get_object_list``:

.. testcode::

from django.utils import timezone
from tastypie.compat import timezone
from myapp.models import MyModel


Expand Down
13 changes: 12 additions & 1 deletion tastypie/compat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import django
from django.conf import settings
from django.contrib.auth import get_user_model # noqa
from django.utils import timezone

try:
from django.urls import NoReverseMatch, reverse, Resolver404, get_script_prefix # noqa
Expand All @@ -15,6 +16,17 @@
else:
from django.middleware.csrf import _check_token_format

# Django 5.0 eliminated the former datetime_safe function, this provides
# some level of backwards compatability for existing tastypie use cases
if django.VERSION < (5, 0):
from django.utils import datetime_safe # noqa: F401
else:
import datetime as datetime_safe # noqa: F401
# Django 5.0 removed this alias - restore it for backwards compatability.
# Django 5.0 essentially completed a lot of the move to zoneinfo, prior to that
# this was an alias that was added in 4.0.
timezone.utc = datetime_safe.timezone.utc

AUTH_USER_MODEL = settings.AUTH_USER_MODEL


Expand Down Expand Up @@ -74,7 +86,6 @@ def compare_sanitized_tokens(request_csrf_token, csrf_token):
return constant_time_compare(_unsalt_cipher_token(request_csrf_token),
_unsalt_cipher_token(csrf_token))


class InvalidTokenFormat(Exception): # noqa
pass
except ImportError: # pragma: no cover
Expand Down
2 changes: 1 addition & 1 deletion tastypie/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
except ImportError:
from django.db.models.fields.related_descriptors import\
ReverseOneToOneDescriptor
from django.utils import datetime_safe
from tastypie.compat import datetime_safe

from tastypie.bundle import Bundle
from tastypie.exceptions import ApiFieldError, NotFound
Expand Down
2 changes: 1 addition & 1 deletion tastypie/utils/timezone.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import datetime
from tastypie.compat import timezone
from django.conf import settings
from django.utils import timezone


def make_aware(value):
Expand Down
3 changes: 2 additions & 1 deletion tests/core/tests/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
from django.http import HttpRequest, QueryDict, Http404
from django.test import TestCase
from django.test.utils import override_settings
from django.utils import timezone

from tastypie.compat import timezone

from tastypie.authentication import BasicAuthentication
from tastypie.authorization import Authorization
Expand Down
9 changes: 7 additions & 2 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
DJANGO_11 = StrictVersion('1.11')
DJANGO_19 = StrictVersion('1.9')
DJANGO_18 = StrictVersion('1.8')
DJANGO_42 = StrictVersion('4.2')

sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))

Expand Down Expand Up @@ -54,14 +55,18 @@
SECRET_KEY = 'verysecret'

# weaker password hashing shoulod allow for faster tests
PASSWORD_HASHERS = (
PASSWORD_HASHERS = [
'django.contrib.auth.hashers.CryptPasswordHasher',
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
'django.contrib.auth.hashers.BCryptPasswordHasher',
'django.contrib.auth.hashers.SHA1PasswordHasher',
'django.contrib.auth.hashers.MD5PasswordHasher',
)
]
# Django 5.0 removed this hasher
if DJANGO_VERSION > DJANGO_42:
PASSWORD_HASHERS.remove('django.contrib.auth.hashers.CryptPasswordHasher')


LOGGING = {
'version': 1,
Expand Down
33 changes: 18 additions & 15 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
envlist =
py{3.6,3.7,3.8,3.9,3.10}-dj{3.2,}
py{3.8,3.9,3.10,3.11}-dj{4.0,4.1,4.2,dev}
py{3.9,3.10,3.11}-dj{5.0}
py{3.6,3.7,3.8,3.9,3.10,3.11}-docs,
py{3.6,3.7,3.8,3.9,3.10,3.11}-flake8,
py{3.8,3.9,3.10,3.11}-flake8-strict
Expand All @@ -14,20 +15,20 @@ setenv =
PYTHONPATH = {toxinidir}:{toxinidir}/tests
PYTHONWARNINGS = always
TESTEXE = {envbindir}/coverage run --append --source=tastypie,tests {envbindir}/django-admin.py
dj{4.0,4.1,4.2,dev}: TESTEXE = {envbindir}/coverage run --append --source=tastypie,tests {envbindir}/django-admin
dj{4.0,4.1,4.2,5.0,dev}: TESTEXE = {envbindir}/coverage run --append --source=tastypie,tests {envbindir}/django-admin

commands =
dj{3.2,4.0,4.1,4.2,dev}: {env:TESTEXE} test -p '*' core.tests --settings=settings_core
dj{3.2,4.0,4.1,4.2,dev}: {env:TESTEXE} test basic.tests --settings=settings_basic
dj{3.2,4.0,4.1,4.2,dev}: {env:TESTEXE} test related_resource.tests --settings=settings_related
dj{3.2,4.0,4.1,4.2,dev}: {env:TESTEXE} test alphanumeric.tests --settings=settings_alphanumeric
dj{3.2,4.0,4.1,4.2,dev}: {env:TESTEXE} test authorization.tests --settings=settings_authorization
dj{3.2,4.0,4.1,4.2,dev}: {env:TESTEXE} test content_gfk.tests --settings=settings_content_gfk
dj{3.2,4.0,4.1,4.2,dev}: {env:TESTEXE} test customuser.tests --settings=settings_customuser
dj{3.2,4.0,4.1,4.2,dev}: {env:TESTEXE} test namespaced.tests --settings=settings_namespaced
dj{3.2,4.0,4.1,4.2,dev}: {env:TESTEXE} test slashless.tests --settings=settings_slashless
dj{3.2,4.0,4.1,4.2,dev}: {env:TESTEXE} test validation.tests --settings=settings_validation
dj{3.2,4.0,4.1,4.2,dev}: {env:TESTEXE} test gis.tests --settings=settings_gis_spatialite
dj{3.2,4.0,4.1,4.2,5.0,dev}: {env:TESTEXE} test -p '*' core.tests --settings=settings_core
dj{3.2,4.0,4.1,4.2,5.0,dev}: {env:TESTEXE} test basic.tests --settings=settings_basic
dj{3.2,4.0,4.1,4.2,5.0,dev}: {env:TESTEXE} test related_resource.tests --settings=settings_related
dj{3.2,4.0,4.1,4.2,5.0,dev}: {env:TESTEXE} test alphanumeric.tests --settings=settings_alphanumeric
dj{3.2,4.0,4.1,4.2,5.0,dev}: {env:TESTEXE} test authorization.tests --settings=settings_authorization
dj{3.2,4.0,4.1,4.2,5.0,dev}: {env:TESTEXE} test content_gfk.tests --settings=settings_content_gfk
dj{3.2,4.0,4.1,4.2,5.0,dev}: {env:TESTEXE} test customuser.tests --settings=settings_customuser
dj{3.2,4.0,4.1,4.2,5.0,dev}: {env:TESTEXE} test namespaced.tests --settings=settings_namespaced
dj{3.2,4.0,4.1,4.2,5.0,dev}: {env:TESTEXE} test slashless.tests --settings=settings_slashless
dj{3.2,4.0,4.1,4.2,5.0,dev}: {env:TESTEXE} test validation.tests --settings=settings_validation
dj{3.2,4.0,4.1,4.2,5.0,dev}: {env:TESTEXE} test gis.tests --settings=settings_gis_spatialite

docs: sphinx-build -W -b html -d {envtmpdir}/doctrees . {envtmpdir}/html
docs: sphinx-build -W -b doctest -d {envtmpdir}/doctrees . {envtmpdir}/html
Expand All @@ -47,14 +48,16 @@ deps =
dj4.0: Django>=4.0,<4.1
dj4.1: Django>=4.1,<4.2
dj4.2: Django>=4.2,<4.3
dj5.0: Django>=5.0,<5.1
djdev: https://github.com/django/django/archive/refs/heads/main.zip

dj{3.2,4.0,4.1,4.2,dev}: python3-digest>=1.8b4
dj{3.2,4.0,4.1,4.2,dev}: -r{toxinidir}/tests/requirements.txt
dj{3.2,4.0,4.1,4.2,dev}: -r{toxinidir}/requirements.txt
dj{3.2,4.0,4.1,4.2,5.0,dev}: -r{toxinidir}/tests/requirements.txt
dj{3.2,4.0,4.1,4.2,5.0,dev}: -r{toxinidir}/requirements.txt

py{3.6,3.7}-docs: Django~=3.2
py{3.8,3.9,3.10,3.11}-docs: Django<4.3
py{3.8,3.9}-docs: Django<4.3
py{3.10,3.11}-docs: Django~=5.0
docs: Sphinx
docs: mock
docs: sphinx_rtd_theme
Expand Down