I'm opening a django console (to narrow the problem) and run this line:
for sesion in SesionJuego.objects.filter(preguntas__respuesta__isnull=True): print sesion,
sesion.pkWhere:
* printing is just a sample operation. I'm getting the same error (I'll describe later) with any loop body.
* SesionJuego is a custom model class, having a `preguntas` attribute which is the reverse side (related_name) of a ForeignKey.
* I have this issue in an atomic view, but I can also reproduce this error in console.
I have 1 SesionJuego element, with 5 (related) questions in the database.
What I expect is that such loop iterates over ONE element, ONCE. What I get is this (see the console below):
So if I iterate I'm getting a non-unique iteration and the second-to-fifth iterations will yield objects without the related `preguntas` (i.e. for those objects, the populated `preguntas` has a `count` of 0).
Is this a bug? Seems it is iterating over the join instead of over the objects. How can I work in a django-way to avoid that?