I have two models one with an int pk and one with a UUIDField pk:
class Bar(models.Model):
id = models.UUIDField(primary_key=True, default=uuid4)
class Bar2(models.Model):
pass
If I try to get these using a value of {} they fail differently. The model with the int pk:
>>> Bar2.objects.all().get(pk={})
TypeError: int() argument must be a string or a number, not 'dict'
whereas:
>>> Bar.objects.all().get(pk={})
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/Users/alex/.virtualenvs/TestPG/lib/python2.7/site-packages/django/db/models/query.py", line 328, in get
num = len(clone)
File "/Users/alex/.virtualenvs/TestPG/lib/python2.7/site-packages/django/db/models/query.py", line 144, in __len__
self._fetch_all()
File "/Users/alex/.virtualenvs/TestPG/lib/python2.7/site-packages/django/db/models/query.py", line 965, in _fetch_all
self._result_cache = list(self.iterator())
File "/Users/alex/.virtualenvs/TestPG/lib/python2.7/site-packages/django/db/models/query.py", line 238, in iterator
results = compiler.execute_sql()
File "/Users/alex/.virtualenvs/TestPG/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 840, in execute_sql
cursor.execute(sql, params)
File "/Users/alex/.virtualenvs/TestPG/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/Users/alex/.virtualenvs/TestPG/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/Users/alex/.virtualenvs/TestPG/lib/python2.7/site-packages/django/db/utils.py", line 97, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Users/alex/.virtualenvs/TestPG/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/Users/alex/.virtualenvs/TestPG/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 318, in execute
return Database.Cursor.execute(self, query, params)
InterfaceError: Error binding parameter 0 - probably unsupported type.
This inconsistency leads to issues like: https://github.com/tomchristie/django-rest-framework/issues/2970
Accepting in a similar vein to #24319. Here's a test that can be used to reproduce the issue:
tests/model_fields/test_uuid.py