Opened 7 years ago

Last modified 2 months ago

#8065 new New feature

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

Reported by: ElliottM Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords: in_bulk filter list
Cc: JMGordon Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no 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 7 years ago.
patch with test and docs

Download all attachments as: .zip

Change History (12)

Changed 7 years ago by ElliottM

patch with test and docs

comment:1 Changed 7 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 7 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 7 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 7 years ago by anonymous

  • milestone post-1.0 deleted

Milestone post-1.0 deleted

comment:5 Changed 5 years ago by adamnelson

Any update on this?

comment:6 Changed 4 years ago by lukeplant

  • Severity set to Normal
  • Type set to New feature

comment:7 Changed 4 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 4 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:9 Changed 4 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 2 months ago by JMGordon

  • Cc JMGordon added
Note: See TracTickets for help on using tickets.
Back to Top