Skip to content

Add a failing test to demonstrate a bug#254

Closed
mjnaderi wants to merge 1 commit intojazzband:masterfrom
mjnaderi:master
Closed

Add a failing test to demonstrate a bug#254
mjnaderi wants to merge 1 commit intojazzband:masterfrom
mjnaderi:master

Conversation

@mjnaderi
Copy link
Copy Markdown
Contributor

@mjnaderi mjnaderi commented Dec 9, 2016

We found a bug in our project, and after investigating, we found where it comes from. So I created a failing test based on our issue.

In this test, removing prefetch_related from this line:

my_teams = Team.objects.filter(user_profiles=user_c).prefetch_related('user_profiles').distinct()

or removing this "for" loop:

for _ in my_teams:
    pass

resolves the issue, and test passes. But with both of them, test fails.

@mjnaderi
Copy link
Copy Markdown
Contributor Author

mjnaderi commented Dec 9, 2016

Another note:
The behavior is different with Sqlite and PostgreSql.

With Sqlite, the test fails with:

Traceback (most recent call last):
  File "/home/naderi/Repos/django-polymorphic/polymorphic/tests.py", line 1379, in test_unknown_issue
    self.assertEqual(len(my_teams[0].user_profiles.all()), 3)
AssertionError: 4 != 3

With PostgreSql, the test fails with:

Traceback (most recent call last):
  File "/home/naderi/Repos/django-polymorphic/polymorphic/tests.py", line 1379, in test_unknown_issue
    self.assertEqual(len(my_teams[0].user_profiles.all()), 3)
AssertionError: 2 != 3

@mjnaderi
Copy link
Copy Markdown
Contributor Author

mjnaderi commented Dec 9, 2016

Now I found issue #68 and pull request #250. Maybe this issue is related to them.


print(my_teams[0].user_profiles.all())
print(my_teams[1].user_profiles.all())
self.assertEqual(len(my_teams[0].user_profiles.all()), 3)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right; you're not ordering you QuerySet, so the first result returned by the DB might be team2. It'll probably fail, occasionally.

@bckohan
Copy link
Copy Markdown
Collaborator

bckohan commented Dec 3, 2025

This PR has been stuck in this state for the last day, so I have pulled the commits and am superceding it with #671
Screenshot 2025-12-03 at 11 00 48 AM

@bckohan bckohan closed this Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants