Django 4.1 QuerySet Filtering on Related Model scenarios with Prefetch Related
I'm trying to filter a Django QuerySet based on a related model's field while utilizing `prefetch_related()` to optimize the query performance. However, when I apply the filter on the related model, it doesn't seem to work as expected. Here's what I have: ```python from django.db import models from django.db.models import Prefetch class Author(models.Model): name = models.CharField(max_length=100) class Book(models.Model): title = models.CharField(max_length=200) author = models.ForeignKey(Author, related_name='books', on_delete=models.CASCADE) # Attempt to filter books by an author's name books = Book.objects.prefetch_related('author').filter(author__name='John Doe') print(books.query) ``` The output of `print(books.query)` shows the correct SQL query being generated, but when I run the code, it returns an empty QuerySet even though I know there are books by 'John Doe'. I confirmed the data exists by running a raw SQL query directly on the database. I've also tried using `select_related()` but that didn't change anything either. Additionally, if I fetch all books without filtering like this: ```python all_books = Book.objects.all() print(all_books.count()) # This returns the expected count ``` I can see that the books are being loaded correctly. I'm using Django 4.1 and PostgreSQL as my database. Could there be an scenario with how I'm combining `prefetch_related` with the filter? I could really use some insights on this, as I've spent considerable time debugging this without any luck.