Opened 8 years ago

Closed 8 months ago

#8065 closed New feature (fixed)

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

Reported by: ElliottM Owned by: bxm156
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords: in_bulk filter list
Cc: JMGordon, 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 8 years ago.
patch with test and docs

Download all attachments as: .zip

Change History (18)

Changed 8 years ago by ElliottM

patch with test and docs

comment:1 Changed 8 years ago by mir

  • milestone set to post-1.0
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed

comment:2 Changed 8 years ago by mtredinnick

  • Resolution set to wontfix
  • Status changed from new to closed

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 8 years ago by anonymous

  • Resolution wontfix deleted
  • Status changed from closed to reopened

"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 8 years ago by anonymous

  • milestone post-1.0 deleted

Milestone post-1.0 deleted

comment:5 Changed 6 years ago by adamnelson

Any update on this?

comment:6 Changed 5 years ago by lukeplant

  • Severity set to Normal
  • Type set to New feature

comment:7 Changed 5 years ago by lukeplant

  • Patch needs improvement set
  • Triage Stage changed from Design decision needed to Accepted

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 5 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:9 Changed 5 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:10 Changed 3 years ago by aaugustin

  • Status changed from reopened to new

comment:11 Changed 13 months ago by JMGordon

  • Cc JMGordon added

comment:12 Changed 10 months ago by timgraham

  • 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 10 months ago by bxm156

  • Owner changed from nobody to bxm156
  • Status changed from new to assigned

comment:15 Changed 8 months ago by PramodBisht

  • Cc pramodpsb@… added

comment:17 Changed 8 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

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