Open ephes opened 5 years ago
class _HashidTaggableManager(_TaggableManager):
def get_prefetch_queryset(self, instances, queryset=None):
result = list(super().get_prefetch_queryset(instances, queryset=queryset))
result[2] = lambda obj: obj._get_pk_val().id
return tuple(result)
Thanks for the report, this is clearly a nasty little bug
Hi *,
first of all: thanks for this awesome package :).
I use django-taggit on models which have a hash_id primary key. At first I thought that this would be enough:
But it turned out that now item.tags.all() was empty on models which were retrieved through querysets with .prefetch_related("tags"). This seemed very odd to me. After some digging in djangos prefetch_related functions, I found out that this line caused the problem. Since obj._get_pk_val() returns an Hashid-object and attrgetter("_prefetch_related_val") returns the integer key the cache keys do not match anymore and an empty queryset gets stored. My current workaround is to use my own _TaggableManager which overwrites get_prefetch_queryset, but this doesn't seem to be very elegant. Maybe there's another way to do it?
Thanks and have a nice day, jochen