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

Fix Django 4 compatibility issues #778

Merged
merged 4 commits into from
Dec 16, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog
~~~~~~~~~~~~

* Add Python 3.10 support.
* Add Django 4.0 support.

2.0.0 (2021-11-14)
~~~~~~~~~~~~~~~~~~
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ classifiers =
Framework :: Django :: 2.2
Framework :: Django :: 3.1
Framework :: Django :: 3.2
Framework :: Django :: 4.0
Intended Audience :: Developers
License :: OSI Approved :: BSD License
Operating System :: OS Independent
Expand Down
15 changes: 14 additions & 1 deletion taggit/managers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import uuid
from operator import attrgetter

import django
from django.conf import settings
from django.contrib.contenttypes.fields import GenericRelation
from django.contrib.contenttypes.models import ContentType
Expand Down Expand Up @@ -666,14 +667,26 @@ def get_joining_columns(self, reverse_join=False):
else:
return (("object_id", self.model._meta.pk.column),)

def get_extra_restriction(self, where_class, alias, related_alias):
def _get_extra_restriction(self, alias, related_alias):
extra_col = self.through._meta.get_field("content_type").column
content_type_ids = [
ContentType.objects.get_for_model(subclass).pk
for subclass in _get_subclasses(self.model)
]
return ExtraJoinRestriction(related_alias, extra_col, content_type_ids)

def _get_extra_restriction_legacy(self, where_class, alias, related_alias):
# this is a shim to maintain compatibility with django < 4.0
return self._get_extra_restriction(alias, related_alias)

# this is required to handle a change in Django 4.0
# https://docs.djangoproject.com/en/4.0/releases/4.0/#miscellaneous
# the signature of the (private) funtion was changed
if django.VERSION < (4, 0):
get_extra_restriction = _get_extra_restriction_legacy
else:
get_extra_restriction = _get_extra_restriction

def get_reverse_joining_columns(self):
return self.get_joining_columns(reverse_join=True)

Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ envlist =
isort
py{36,37,38,39}-dj{22,31}
py{36,37,38,39,310}-dj32
py{38,39,310}-dj40
py{38,39,310}-djmain
docs

Expand All @@ -22,6 +23,7 @@ deps =
dj22: Django>=2.2,<3.0
dj31: Django>=3.1,<3.2
dj32: Django>=3.2,<3.3
dj40: Django>=4.0,<4.1
djmain: https://github.com/django/django/archive/main.tar.gz
coverage
djangorestframework
Expand Down