Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a failing test to demonstrate a bug #254

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add a failing test to demonstrate a bug #254

wants to merge 1 commit into from

Conversation

mjnaderi
Copy link

@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
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
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
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.

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.

2 participants