Monday, June 18, 2018

queryset appears empty in debugger during testing, but not in console

Hello,

I'm testing REST APIs with rest_framework.test.APITestCase, using their client for making requests and model_mommy for creating objects in the setUp() method.
The general working is quite simple: the view is supposed to fetch a User and an object, and assign permissions for the former to the latter by means of django-guardian's assign_perm; the test creates a user and a group in the setUp method, then the actual test performs a POST passing their pk's as payload.
The issue I'm seeing, is that when the User.objects.filter(pk__in=people_ids) instruction is executed, the value I see in the debugger is that of an empty queryset, while if I type the exact same line in a console connected to the same session as the debugger I see the actual value being found.
Then the view gets to the assign_perm instruction, and it crashes with an IndexError: list index out of range error on the first evaluation of the queryset itself, which happens on the for loop at line 247 in the file core.py of the django-guardian library.

Is there something obvious that I should be looking at, because I really cannot wrap my head around this.

Thanks,
Michele

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bf0050d0-525a-4844-834c-6c3eff2c04b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment