﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35690	Calling queryset.in_bulk() after queryset.values() or queryset.values_list() results in unhelpful error	john-parton	john-parton	"Calling
{{{
MyModel.objects.values().in_bulk()
}}}

Results in a rather annoying error message that doesn't help the user.


{{{
Traceback (most recent call last):
  File ""<console>"", line 1, in <module>
  File ""/home/john/Code/ecom/.venv/lib/python3.12/site-packages/django/db/models/query.py"", line 1156, in in_bulk
    return {getattr(obj, field_name): obj for obj in qs}
            ^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'dict' object has no attribute 'pk'
}}}

This is because the `in_bulk` method assumes that the queryset has the default `_iterable_class` (`ModelIterable`) and is attempting to access a property on an object, but the `_iterable_class` returns dictionaries.

The correct behavior should be either to:

1. Raise a more helpful error if the user attempts to call `in_bulk()` where the _iterable_class isn't the standard ModelIterable; or
2. Define behavior for when `in_bulk()` is called in that case. (I think that might be rather challenging, so Behavior 1 is probably the better option.)

"	Cleanup/optimization	closed	Database layer (models, ORM)	5.1	Normal	fixed			Ready for checkin	1	0	0	0	0	0
