Opened 10 months ago

Last modified 10 months ago

#35110 closed New feature

in_bulk does not work with annotated fields, nor on foreign key — at Initial Version

Reported by: Cody Towstik Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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("personemail")

).distinct(

"email_lower"

).in_bulk(

emails_to_process, fieldname="email_lower"

)

# foreign key case
Customer.objects.distinct("personemail").in_bulk(emails_to_process, fieldname="personemail)

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top