Opened 10 years ago

Closed 3 years ago

#8065 closed New feature (fixed)

Calling queyset.in_bulk (without any arguments) should evaluate the whole queryset.

Reported by: ElliottM Owned by: Bryan Marty
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords: in_bulk filter list
Cc: Joseph Gordon, pramodpsb@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no


in_bulk() works well if you know beforehand which ids you want to pull out. It becomes irritating, however, if you want to map an entire queryset at once.

Right now you have to do the following:

id_list=list(Book.objects.filter(author__name='Douglas Adams').values_list('id', flat=True))

With the patch included, the following will now work:

bulk=Book.objects.filter(author__name='Douglas Adams').in_bulk()

I feel the second way is easier to read, and I really don't see any reason why people shouldn't be allowed to do this.

Attachments (1)

in_bulk.diff (3.6 KB) - added by ElliottM 10 years ago.
patch with test and docs

Download all attachments as: .zip

Change History (18)

Changed 10 years ago by ElliottM

Attachment: in_bulk.diff added

patch with test and docs

comment:1 Changed 10 years ago by Michael Radziej

milestone: post-1.0
Triage Stage: UnreviewedDesign decision needed

comment:2 Changed 10 years ago by Malcolm Tredinnick

Resolution: wontfix
Status: newclosed

This would be a backwards incompatible API change (the docs say that calling in_bulk() with no parameters returns an empty dictionary).

It's also a one line call to do it yourself (dict([(, o) for o in qs])), so it doesn't really need to be added to the API.

comment:3 Changed 10 years ago by anonymous

Resolution: wontfix
Status: closedreopened

"If you pass in_bulk() an empty list, you'll get an empty dictionary."

Passing it an empty list is quite different than passing no parameters at all, so all previous code would be compatible. queryset.in_bulk() is also a lot easier to read than the code snippet you posted.

comment:4 Changed 10 years ago by (none)

milestone: post-1.0

Milestone post-1.0 deleted

comment:5 Changed 9 years ago by Adam Nelson

Any update on this?

comment:6 Changed 8 years ago by Luke Plant

Severity: Normal
Type: New feature

comment:7 Changed 8 years ago by Luke Plant

Patch needs improvement: set
Triage Stage: Design decision neededAccepted

This looks like a good idea to me, and not backwards incompatible, as noted by anonymous.

The patch needs work - unittests instead of doctests, and a proper versionadded directive in the docs.

comment:8 Changed 7 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:9 Changed 7 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:10 Changed 6 years ago by Aymeric Augustin

Status: reopenednew

comment:11 Changed 3 years ago by Joseph Gordon

Cc: Joseph Gordon added

comment:12 Changed 3 years ago by Tim Graham

Easy pickings: set

Marking as "Easy pickings" since it looks to me like updating this patch shouldn't be too difficult. Check it with the PatchReviewChecklist.

comment:13 Changed 3 years ago by Bryan Marty

Owner: changed from nobody to Bryan Marty
Status: newassigned

comment:15 Changed 3 years ago by Pramod Bisht

Cc: pramodpsb@… added

comment:17 Changed 3 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 62ca2dea:

Fixed #8065 -- Made id_list an optional argument for QuerySet.in_bulk().

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