Opened 16 years ago
Closed 9 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)
Change History (18)
by , 16 years ago
Attachment: | in_bulk.diff added |
---|
comment:1 by , 16 years ago
milestone: | → post-1.0 |
---|---|
Triage Stage: | Unreviewed → Design decision needed |
comment:2 by , 16 years ago
Resolution: | → wontfix |
---|---|
Status: | new → 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.pk, o) for o in qs])
), so it doesn't really need to be added to the API.
comment:3 by , 16 years ago
Resolution: | wontfix |
---|---|
Status: | closed → reopened |
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:6 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → New feature |
comment:7 by , 14 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Design decision needed → 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:10 by , 12 years ago
Status: | reopened → new |
---|
comment:11 by , 9 years ago
Cc: | added |
---|
comment:12 by , 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 , 9 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:14 by , 9 years ago
comment:15 by , 9 years ago
Cc: | added |
---|
comment:16 by , 9 years ago
Patch needs improvement: | unset |
---|
patch with test and docs