I have a model Link:
class Link(models.Model):
tags = TaggableManager(through=LinkTag)
actions = GenericRelation(
Action,
related_query_name='link',
content_type_field='action_object_content_type',
object_id_field='action_object_object_id',
)
The Action model is here.
I need to find all actions on links with tag "test1":
tag=Tag.objects.filter(name="test1").first()
Action.objects.filter(link__tags__name__in=[tag])
# also tried with: Action.objects.filter(link__tags__name__in=[tag.name])
However, this gives an error:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedFunction: operator does not exist: character varying = integer
LINE 1: ... ON ("actstream_action"."action_object_object_id" = "links_l...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python3.9/site-packages/django/db/models/query.py", line 256, in __repr__
data = list(self[:REPR_OUTPUT_SIZE + 1])
File "/usr/local/lib/python3.9/site-packages/django/db/models/query.py", line 262, in __len__
self._fetch_all()
File "/usr/local/lib/python3.9/site-packages/django/db/models/query.py", line 1324, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/usr/local/lib/python3.9/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 "/usr/local/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 1175, in execute_sql
cursor.execute(sql, params)
File "/usr/local/lib/python3.9/site-packages/django/db/backends/utils.py", line 98, in execute
return super().execute(sql, params)
File "/usr/local/lib/python3.9/site-packages/django/db/backends/utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/usr/local/lib/python3.9/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/usr/local/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python3.9/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/usr/local/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: operator does not exist: character varying = integer
LINE 1: ... ON ("actstream_action"."action_object_object_id" = "links_l...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
I also tried with:
Action.objects.filter(action_object_content_type=ContentType.objects.get_for_model(Link), link__tags__name__in=[tag])
# Also tried with:
# Action.objects.filter(action_object_content_type=ContentType.objects.get_for_model(Link), link__tags__name__in=[tag.name])
I'm having the same error.
Note: Link.objects.filter(tags__name__in=[tag])
works fine.
Any idea how to fix this?