django-fastdev icon indicating copy to clipboard operation
django-fastdev copied to clipboard

`User.objects.get(4)` should give a good error message

Open boxed opened this issue 3 years ago • 3 comments

The current error in django is:

TypeError: cannot unpack non-iterable int object

If you do User.objects.get('123') you get:

ValueError: too many values to unpack (expected 2)

boxed avatar Feb 21 '22 00:02 boxed

What error message should be shown?

Marlysson avatar Feb 22 '22 05:02 Marlysson

Maybe something like:

"Got 4, but get/filter takes keyword arguments or Q objects. Maybe you meant pk=4?"

boxed avatar Feb 22 '22 05:02 boxed

I think the check that should be made is that none of the *args should be non-Q-objects.

boxed avatar Feb 22 '22 07:02 boxed