From 77db999859d9b5a960ce383b14221371f225c50c Mon Sep 17 00:00:00 2001 From: Bernd Wechner Date: Mon, 28 Jan 2019 14:52:16 +1100 Subject: [PATCH 1/4] Fixed bug in which DISTINCT clauses were forcibly removed from supplied querysets I was supplyin a queryset which was already distcint! And moreover I am using .distinct(field) in order to make a complex inetraction between url filters and Window functions work. Works a dream in fact except that url_filter was clobberig the necessary DISTINCT ON clause in my query. THis is where it happened and it was because it paid no heed to the existing status of the querie's distinct() setting. It neeed only apply distinct() if the caller has anot already applied on (not least as called knows what fields they need to distinguish on. --- url_filter/backends/django.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/url_filter/backends/django.py b/url_filter/backends/django.py index 6a78a2f..1040970 100644 --- a/url_filter/backends/django.py +++ b/url_filter/backends/django.py @@ -113,7 +113,8 @@ def filter_by_specs(self, queryset): queryset = queryset.exclude(**{lookup: value}) to_many = self._is_any_to_many() - return queryset.distinct() if to_many and (include or exclude) else queryset + is_distinct = queryset.distinct() + return queryset.distinct() if (not is_distinct) and to_many and (include or exclude) else queryset def _is_any_to_many(self): return any(self._is_to_many(self.model, i.components) for i in self.regular_specs) From 489082203553a0257f2227479f64fa0899fdedf6 Mon Sep 17 00:00:00 2001 From: Bernd Wechner Date: Mon, 28 Jan 2019 14:57:26 +1100 Subject: [PATCH 2/4] Fixed a typo in the Makefile Simple spelling mistake. It's quiet not quite. Well a comix might say it's quite quiet ;-). --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 7724902..0df216c 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ help: ## show help install: ## install all requirements including for testing pip install -r requirements-dev.txt -install-quite: ## same as install but pipes all output to /dev/null +install-quiet: ## same as install but pipes all output to /dev/null pip install -r requirements-dev.txt > /dev/null clean: clean-build clean-pyc ## remove all artifacts From 7489fb00b882deeee997bc9a7a3b8872ae06537f Mon Sep 17 00:00:00 2001 From: Miroslav Shubernetskiy Date: Mon, 28 Jan 2019 16:59:55 +1100 Subject: [PATCH 3/4] Update url_filter/backends/django.py Sounds good. Thanks for the suggestion! Am on a learning curve here. And of course the only goal is that the stated one, that an existing DISTINCT clause be honored and not clobbered. Co-Authored-By: bernd-wechner --- url_filter/backends/django.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/url_filter/backends/django.py b/url_filter/backends/django.py index 1040970..fcbfb74 100644 --- a/url_filter/backends/django.py +++ b/url_filter/backends/django.py @@ -113,7 +113,7 @@ def filter_by_specs(self, queryset): queryset = queryset.exclude(**{lookup: value}) to_many = self._is_any_to_many() - is_distinct = queryset.distinct() + is_distinct = bool(queryset.query.distinct_fields) return queryset.distinct() if (not is_distinct) and to_many and (include or exclude) else queryset def _is_any_to_many(self): From eef1d00e1abbad1e3538fee8014cc61dac511ffe Mon Sep 17 00:00:00 2001 From: Bernd Wechner Date: Tue, 1 Mar 2022 20:42:08 +1100 Subject: [PATCH 4/4] Django 4 Incompatibility fixed --- url_filter/validators.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/url_filter/validators.py b/url_filter/validators.py index d40d0ca..fa6c5d8 100644 --- a/url_filter/validators.py +++ b/url_filter/validators.py @@ -6,7 +6,7 @@ MinLengthValidator as _MinLengthValidator, ) from django.utils.deconstruct import deconstructible -from django.utils.translation import ungettext_lazy +from django.utils.translation import ngettext_lazy @deconstructible @@ -16,7 +16,7 @@ class MinLengthValidator(_MinLengthValidator): """ code = "min_length" - message = ungettext_lazy( + message = ngettext_lazy( "Ensure this value has at least %(limit_value)d items (it has %(show_value)d).", "Ensure this value has at least %(limit_value)d items (it has %(show_value)d).", "limit_value", @@ -36,7 +36,7 @@ class MaxLengthValidator(_MaxLengthValidator): """ code = "max_length" - message = ungettext_lazy( + message = ngettext_lazy( "Ensure this value has at most %(limit_value)d items (it has %(show_value)d).", "Ensure this value has at most %(limit_value)d items (it has %(show_value)d).", "limit_value",