Filter by string broken starting with Django 3.2
marcushallett opened this issue · 0 comments
marcushallett commented
Filtering by string is broken starting with Django 3.2.
Here's the behavior using the example project:
Undesired Behavior: Django>=3.2.0 django-tagulous==1.1.0
>>> Person.objects.filter(hobbies='coding')
Traceback (most recent call last):
File "C:\Users\marcu\Downloads\django-tagulous-develop\venv\lib\site-packages\django\db\models\fields\__init__.py", line 1823, in get_prep_value
return int(value)
ValueError: invalid literal for int() with base 10: 'coding'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\Users\marcu\Downloads\django-tagulous-develop\venv\lib\site-packages\django\db\models\manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\marcu\Downloads\django-tagulous-develop\venv\lib\site-packages\django\db\models\query.py", line 941, in filter
return self._filter_or_exclude(False, args, kwargs)
File "C:\Users\marcu\Downloads\django-tagulous-develop\venv\lib\site-packages\tagulous\models\tagged.py", line 130, in _filter_or_exclude
qs = super(TaggedQuerySet, self)._filter_or_exclude(
_filter_or_exclude
clone._filter_or_exclude_inplace(negate, args, kwargs)
File "C:\Users\marcu\Downloads\django-tagulous-develop\venv\lib\site-packages\django\db\models\query.py", line 968, in _filter_or_exclude_inplace
self._query.add_q(Q(*args, **kwargs))
File "C:\Users\marcu\Downloads\django-tagulous-develop\venv\lib\site-packages\django\db\models\sql\query.py", line 1396, in add_q
clause, _ = self._add_q(q_object, self.used_aliases)
File "C:\Users\marcu\Downloads\django-tagulous-develop\venv\lib\site-packages\django\db\models\sql\query.py", line 1415, in _add_q
child_clause, needed_inner = self.build_filter(
File "C:\Users\marcu\Downloads\django-tagulous-develop\venv\lib\site-packages\django\db\models\sql\query.py", line 1350, in build_filter
condition = self.build_lookup(lookups, col, value)
File "C:\Users\marcu\Downloads\django-tagulous-develop\venv\lib\site-packages\django\db\models\sql\query.py", line 1196, in build_lookup
lookup = lookup_class(lhs, rhs)
File "C:\Users\marcu\Downloads\django-tagulous-develop\venv\lib\site-packages\django\db\models\lookups.py", line 25, i self.rhs = self.get_prep_lookup()
File "C:\Users\marcu\Downloads\django-tagulous-develop\venv\lib\site-packages\django\db\models\fields\related_lookups.py", line 117, in get_prep_lookup
self.rhs = target_field.get_prep_value(self.rhs)
File "C:\Users\marcu\Downloads\django-tagulous-develop\venv\lib\site-packages\django\db\models\fields\__init__.py", line 1825, in get_prep_value
raise e.__class__(
ValueError: Field 'id' expected a number but got 'coding'.
Desired Behavior: Django<=3.1.8 django-tagulous==1.1.0
>>> Person.objects.filter(hobbies='coding')
<CastTaggedQuerySet [<Person: Person object (2)>]>
I haven't yet investigated the matter any further.