Opened 16 years ago

Closed 8 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: dev
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

Description

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))
bulk=Book.objects.in_bulk(id_list)

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 16 years ago.
patch with test and docs

Download all attachments as: .zip

Change History (18)

by ElliottM, 16 years ago

Attachment: in_bulk.diff added

patch with test and docs

comment:1 by Michael Radziej, 16 years ago

milestone: post-1.0
Triage Stage: UnreviewedDesign decision needed

comment:2 by Malcolm Tredinnick, 16 years ago

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.pk, o) for o in qs])), so it doesn't really need to be added to the API.

comment:3 by anonymous, 16 years ago

Resolution: wontfix
Status: closedreopened

http://docs.djangoproject.com/en/dev/ref/models/querysets/#in-bulk-id-list

"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 by (none), 15 years ago

milestone: post-1.0

Milestone post-1.0 deleted

comment:5 by Adam Nelson, 14 years ago

Any update on this?

comment:6 by Luke Plant, 13 years ago

Severity: Normal
Type: New feature

comment:7 by Luke Plant, 13 years ago

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 by Aymeric Augustin, 12 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:9 by Aymeric Augustin, 12 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:10 by Aymeric Augustin, 11 years ago

Status: reopenednew

comment:11 by Joseph Gordon, 9 years ago

Cc: Joseph Gordon added

comment:12 by Tim Graham, 9 years ago

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 by Bryan Marty, 9 years ago

Owner: changed from nobody to Bryan Marty
Status: newassigned

comment:15 by Pramod Bisht, 8 years ago

Cc: pramodpsb@… added

comment:17 by Tim Graham <timograham@…>, 8 years ago

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