Opened 3 years ago

Closed 3 years ago

#17350 closed New feature (worksforme)

in_bulk should use duck typing so that listy-objects can be used, like ValuesListQuerySet

Reported by: umbrae@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.3
Severity: Normal Keywords: queryset, valueslistqueryset, db
Cc: umbrae@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Currently, using a ValuesListQuerySet as a parameter to in_bulk returns an exception, even with flat=True:

AssertionError: in_bulk() must be provided with a list of IDs.

This is due to this line in query.py (line 416 in 1.3) :

assert isinstance(id_list, (tuple,  list, set, frozenset)), \
                "in_bulk() must be provided with a list of IDs.

Which requires a certain type, rather than just something that can be iterated upon. I think it'd be more valuable if it was just something iterable, like ValuesListQuerySet is.

Change History (1)

comment:1 Changed 3 years ago by aaugustin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to worksforme
  • Status changed from new to closed

As far as I can tell, this problem no longer exists.

Here are all the occurrences of assert isinstance in trunk:

django/core/servers/basehttp.py:        assert isinstance(data, str), "write() argument must be string"
django/db/models/fields/related.py:            assert isinstance(to, basestring), "'to' must be either a model, a model name or the string %r" % RECURSIVE_RELATIONSHIP_CONSTANT
django/db/models/fields/related.py:            assert isinstance(to, basestring), "%s(%r) is invalid. First parameter to ForeignKey must be either a model, a model name, or the string %r" % (self.__class__.__name__, to, RECURSIVE_RELATIONSHIP_CONSTANT)
django/db/models/fields/related.py:            assert isinstance(to, basestring), "%s(%r) is invalid. First parameter to ManyToManyField must be either a model, a model name, or the string %r" % (self.__class__.__name__, to, RECURSIVE_RELATIONSHIP_CONSTANT)
django/db/models/sql/subqueries.py:        assert isinstance(field, DateField), "%r isn't a DateField." \
Note: See TracTickets for help on using tickets.
Back to Top