#22268: values_list() on a ManyToManyField returns extra None's when iterated over. -------------------------------------+------------------------------------- Reporter: k_sze | Owner: nobody Type: Bug | Status: new Component: Database layer | Version: master (models, ORM) | Resolution: Severity: Normal | Triage Stage: Accepted Keywords: orm, values_list, | Needs documentation: 0 ManyToManyField | Patch needs improvement: 0 Has patch: 0 | UI/UX: 0 Needs tests: 0 | Easy pickings: 0 | -------------------------------------+-------------------------------------
Comment (by k_sze): And I believe the problem is even more serious when the values_list is querying for a nullable field of a ManyToManyField. For example, if I modify the Student class and add a new field: {{{ class Student(models.Model): surname = models.CharField(max_length=255) given_name = models.CharField(max_length=255) year_of_birth = models.SmallIntegerField(null=True) }}} And then I make this query: {{{ >>> Class.objects.values_list('students__year_of_birth', flat=True) [None, None] }}} It becomes ambiguous where the `None`s come from: one of the `None`s is from john_smith, who has a null year_of_birth, the other `None` is because the other class has no student at all. -- Ticket URL: <https://code.djangoproject.com/ticket/22268#comment:7> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.dea9d3cb96574b303b31d1da8b981133%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.