From 7000b40159957ed3af85224707c510af952a7b28 Mon Sep 17 00:00:00 2001 From: Lena Voytek <lena.voytek@canonical.com> Date: Tue, 1 Aug 2023 14:07:16 -0700 Subject: [PATCH 1/2] Fix Django 4.2 compatibility by handling FullResultSet exceptions --- .../Check-FullResultSet-exception.patch | 54 +++++++++++++++++++ debian/patches/series | 1 + 2 files changed, 55 insertions(+) create mode 100644 debian/patches/django-4.x-fixes/Check-FullResultSet-exception.patch diff --git a/debian/patches/django-4.x-fixes/Check-FullResultSet-exception.patch b/debian/patches/django-4.x-fixes/Check-FullResultSet-exception.patch new file mode 100644 index 0000000..5e7e88c --- /dev/null +++ b/debian/patches/django-4.x-fixes/Check-FullResultSet-exception.patch @@ -0,0 +1,54 @@ +Description: Ignore FullResultSet exception introduced in Django 4.2 + As of version 4.2 Django added an exception during query generation when a + query matches everything contained in a table. Since the + models.usage_for_queryset function is meant to handle this case, this patch + instead uses the exception to determine if extra criteria are required. This + effectively replaces the if statement that determines if a "where" value was + generated. The if statement is maintained along with the ImportError skip to + keep compatibility with older Django versions. +Author: Lena Voytek <lena.voytek@canonical.com> +Last-Update: 2023-08-01 +--- +This patch header follows DEP-3: http://dep.debian.net/deps/dep3/ +--- a/tagging/models.py ++++ b/tagging/models.py +@@ -9,6 +9,12 @@ + from django.utils.encoding import smart_str + from django.utils.translation import gettext_lazy as _ + ++# FullResultSet exception is new to Django 4.2 ++try: ++ from django.core.exceptions import FullResultSet ++except ImportError: ++ pass ++ + from tagging import settings + from tagging.utils import LOGARITHMIC + from tagging.utils import calculate_cloud +@@ -177,13 +183,21 @@ + Passing a value for ``min_count`` implies ``counts=True``. + """ + compiler = queryset.query.get_compiler(using=queryset.db) +- where, params = compiler.compile(queryset.query.where) +- extra_joins = ' '.join(compiler.get_from_clause()[0][1:]) ++ params = [] ++ ++ try: ++ where, params = compiler.compile(queryset.query.where) ++ ++ if where: ++ extra_criteria = 'AND %s' % where ++ else: ++ extra_criteria = '' + +- if where: +- extra_criteria = 'AND %s' % where +- else: ++ except FullResultSet: + extra_criteria = '' ++ ++ extra_joins = ' '.join(compiler.get_from_clause()[0][1:]) ++ + return self._get_usage(queryset.model, counts, min_count, + extra_joins, extra_criteria, params) + diff --git a/debian/patches/series b/debian/patches/series index 9c3c21a..608099b 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -2,4 +2,5 @@ Use-local-inventory-for-intersphinx.patch django-4.x-fixes/Use-smart_str-instead-of-deprecated-smart_text-Django-fun.patch django-4.x-fixes/Use-re_path-instead-of-deprecated-url-Django-function.patch django-4.x-fixes/Add-support-for-Django-4-compatibility.patch +django-4.x-fixes/Check-FullResultSet-exception.patch python3.11.patch -- GitLab From 7a44e6510759fb1bb8ae915397cdd34ce02a521d Mon Sep 17 00:00:00 2001 From: Lena Voytek <lena.voytek@canonical.com> Date: Tue, 8 Aug 2023 13:17:03 -0700 Subject: [PATCH 2/2] update changelog --- debian/changelog | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/debian/changelog b/debian/changelog index f0ead9f..23e5a11 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +python-django-tagging (1:0.5.0-5) UNRELEASED; urgency=medium + + * Add Check-FullResultSet-exception.patch to fix Django 4.2 + compatibility by handling FullResultSet exceptions + + -- Lena Voytek <lena.voytek@canonical.com> Tue, 08 Aug 2023 13:14:46 -0700 + python-django-tagging (1:0.5.0-4) unstable; urgency=medium * Team upload. -- GitLab