pythondjangodjango-modelsdjango-taggit

django 4.0rc1 and django-taggit "TypeError: get_extra_restriction() missing 1 required positional argument: 'related_alias'" on filtering by Tag


After upgrading Django to 4.0rc1, wherever I try to filter Objects by it's Tag (django-taggit)

entrys = Entry.objects.filter(tags__name__in=["Tag1", "Tag2"])

or

entrys = Entry.objects.filter(tags__id=tag.id)

I get the following error:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/dirkb/.venv/lib/python3.8/site-packages/django/db/models/query.py", line 256, in __repr__
    data = list(self[:REPR_OUTPUT_SIZE + 1])
  File "/dirkb/.venv/lib/python3.8/site-packages/django/db/models/query.py", line 280, in __iter__
    self._fetch_all()
  File "/dirkb/.venv/lib/python3.8/site-packages/django/db/models/query.py", line 1354, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/dirkb/.venv/lib/python3.8/site-packages/django/db/models/query.py", line 51, in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
  File "/dirkb/.venv/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1189, in execute_sql
    sql, params = self.as_sql()
  File "/dirkb/.venv/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 545, in as_sql
    from_, f_params = self.get_from_clause()
  File "/dirkb/.venv/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 833, in get_from_clause
    clause_sql, clause_params = self.compile(from_clause)
  File "/dirkb/.venv/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 463, in compile
    sql, params = node.as_sql(self, self.connection)
  File "/dirkb/.venv/lib/python3.8/site-packages/django/db/models/sql/datastructures.py", line 81, in as_sql
    extra_cond = self.join_field.get_extra_restriction(self.table_alias, self.parent_alias)
  File "/dirkb/.venv/lib/python3.8/site-packages/django/db/models/fields/reverse_related.py", line 168, in get_extra_restriction
    return self.field.get_extra_restriction(related_alias, alias)
TypeError: get_extra_restriction() missing 1 required positional argument: 'related_alias'

Does anyone have a solution or a workaround?


Solution

  • This is an error from django-taggit.

    They have just pushed a commit that fixes this. To install this you can first uninstall the current version and then install it from git.

    pip uninstall django-taggit
    pip install git+https://github.com/jazzband/django-taggit.git@d0833966d357ed1e1b9b1f40c39c1ed99affbf9b