-
Notifications
You must be signed in to change notification settings - Fork 770
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
Failing test for ChoiceField eagerly evaluating choices #1648
Failing test for ChoiceField eagerly evaluating choices #1648
Conversation
@carltongibson that should help^ In case it helps, that test passes when backported on top of 23.2 and fails with 23.3 |
Great. Thanks. Let me have a look. 👀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @craigds.
Since the callable is wrapped by the iterator, it's being cast to a list in super class (forms.ChoiceField
):
File ".../django-filter/django_filters/fields.py", line 284, in choices
super(ChoiceIteratorMixin, self.__class__).choices.__set__(self, value)
File ".../django/forms/fields.py", line 880, in _set_choices
value = list(value)
(Django stable/4.2.x)
In order avoid that I think we need to bypass the superclass setter for Django<5.0.
Something like:
diff --git a/django_filters/fields.py b/django_filters/fields.py
index 3a34365..d6ac79c 100644
--- a/django_filters/fields.py
+++ b/django_filters/fields.py
@@ -275,13 +275,13 @@ class ChoiceIteratorMixin:
def choices(self, value):
if DJANGO_50:
value = self.iterator(self, value)
+ # Simple `super()` syntax for calling a parent property setter is
+ # unsupported. See https://github.com/python/cpython/issues/59170
+ super(ChoiceIteratorMixin, self.__class__).choices.__set__(self, value)
else:
super()._set_choices(value)
value = self.iterator(self, self._choices)
-
- # Simple `super()` syntax for calling a parent property setter is
- # unsupported. See https://github.com/python/cpython/issues/59170
- super(ChoiceIteratorMixin, self.__class__).choices.__set__(self, value)
+ self._choices = self.widget.choices = value
Fancy trying that?
cc @ngnpope
Thanks for the ping @carltongibson. So, yes, it looks as though I was a little too optimistic there - your proposed patch looks like the right approach. |
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
thanks, sorry I didn't get around to submitting a proper fix |
No problem @craigds. The reproduce was the key thing. 🎁 |
…on#1648) * Failing test for ChoiceField eagerly evaluating choices * Fixed regression in choices setter for Django 4.2. --------- Co-authored-by: Carlton Gibson <[email protected]>
* Failing test for ChoiceField eagerly evaluating choices * Fixed regression in choices setter for Django 4.2. --------- Co-authored-by: Carlton Gibson <[email protected]>
refs #1625