#35110: in_bulk does not work with annotated fields, nor on foreign key -------------------------------------+------------------------------------- Reporter: Cody | Owner: nobody Towstik | Type: Bug | Status: new Component: Database | Version: 5.0 layer (models, ORM) | Severity: Normal | Keywords: Triage Stage: | Has patch: 0 Unreviewed | Needs documentation: 0 | Needs tests: 0 Patch needs improvement: 0 | Easy pickings: 0 UI/UX: 0 | -------------------------------------+------------------------------------- in_bulk does some checks about the fields on the model using the class `_meta`. It does not consider that fields can be annotated, or exist on another related model.
However, the code that does all the processing seems like it could handle both cases. In both cases, you can make the field distinct. class Person(models.Model): email = models.CharField() class Customer(models.Model): person = models.ForeignKey("Person") emails_to_process = [ "a", "b", "c" ] # annotate case Customer.objects.annotate( email_lower=Lower("person__email") ).distinct( "email_lower" ).in_bulk( emails_to_process, fieldname="email_lower" ) # foreign key case Customer.objects.distinct("person__email").in_bulk(emails_to_process, fieldname="person__email) -- Ticket URL: <https://code.djangoproject.com/ticket/35110> 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 view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/0107018d00f83624-c276d833-d02a-4deb-8ce3-28e95cf9f0bc-000000%40eu-central-1.amazonses.com.