[Django] #24859: UUIDField does not Properly Raise TyperError

70 views
Skip to first unread message

Django

unread,
May 26, 2015, 3:40:08 PM5/26/15
to django-...@googlegroups.com
#24859: UUIDField does not Properly Raise TyperError
-------------------------------+--------------------
Reporter: cancan101 | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
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

--
Ticket URL: <https://code.djangoproject.com/ticket/24859>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 27, 2015, 1:56:38 PM5/27/15
to django-...@googlegroups.com
#24859: UUIDField does not Properly Raise TyperError
-------------------------------------+-------------------------------------
Reporter: cancan101 | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: => 0
* component: Uncategorized => Database layer (models, ORM)
* needs_tests: => 0
* needs_docs: => 0
* type: Bug => Cleanup/optimization
* stage: Unreviewed => Accepted


Comment:

Accepting in a similar vein to #24319. Here's a test that can be used to
reproduce the issue:
{{{
#!diff
diff --git a/tests/model_fields/test_uuid.py
b/tests/model_fields/test_uuid.py
index 21c2869..95d47b5 100644
--- a/tests/model_fields/test_uuid.py
+++ b/tests/model_fields/test_uuid.py
@@ -37,6 +37,9 @@ class TestSaveLoad(TestCase):
loaded = NullableUUIDModel.objects.get()
self.assertEqual(loaded.field, None)

+ def test_pk_validated(self):
+ PrimaryKeyUUIDModel.objects.get(pk={})
+
def test_wrong_value(self):
self.assertRaisesMessage(
ValueError, 'badly formed hexadecimal UUID string',
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24859#comment:1>

Django

unread,
May 27, 2015, 1:57:05 PM5/27/15
to django-...@googlegroups.com
#24859: UUIDField does not validate query value
-------------------------------------+-------------------------------------
Reporter: cancan101 | Owner: nobody

Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

--
Ticket URL: <https://code.djangoproject.com/ticket/24859#comment:2>

Django

unread,
Jun 4, 2015, 9:53:29 AM6/4/15
to django-...@googlegroups.com
#24859: UUIDField does not validate query value
-------------------------------------+-------------------------------------
Reporter: cancan101 | Owner: nobody

Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by cole):

* has_patch: 0 => 1


Comment:

https://github.com/django/django/pull/4758 should fix this.

--
Ticket URL: <https://code.djangoproject.com/ticket/24859#comment:3>

Django

unread,
Jun 4, 2015, 9:59:16 AM6/4/15
to django-...@googlegroups.com
#24859: UUIDField does not validate query value
-------------------------------------+-------------------------------------
Reporter: cancan101 | Owner: nobody

Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by cole):

* cc: hi@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/24859#comment:4>

Django

unread,
Jun 4, 2015, 9:59:28 AM6/4/15
to django-...@googlegroups.com
#24859: UUIDField does not validate query value
-------------------------------------+-------------------------------------
Reporter: cancan101 | Owner: nobody

Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by mjtamlyn):

* cc: hi@… (removed)
* needs_better_patch: 0 => 1
* easy: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/24859#comment:5>

Django

unread,
Jun 4, 2015, 9:59:48 AM6/4/15
to django-...@googlegroups.com
#24859: UUIDField does not validate query value
-------------------------------------+-------------------------------------
Reporter: cancan101 | Owner: nobody

Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by mjtamlyn):

* cc: hi@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/24859#comment:6>

Django

unread,
Jun 4, 2015, 10:11:05 AM6/4/15
to django-...@googlegroups.com
#24859: UUIDField does not validate query value
-------------------------------------+-------------------------------------
Reporter: cancan101 | Owner: nobody

Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by cole):

OK, patch revised.

--
Ticket URL: <https://code.djangoproject.com/ticket/24859#comment:7>

Django

unread,
Jun 4, 2015, 10:56:38 AM6/4/15
to django-...@googlegroups.com
#24859: UUIDField does not validate query value
-------------------------------------+-------------------------------------
Reporter: cancan101 | Owner:
Type: | iamsteadman
Cleanup/optimization | Status: assigned

Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by iamsteadman):

* owner: nobody => iamsteadman
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/24859#comment:8>

Django

unread,
Jun 4, 2015, 11:02:43 AM6/4/15
to django-...@googlegroups.com
#24859: UUIDField does not validate query value
-------------------------------------+-------------------------------------
Reporter: cancan101 | Owner:
Type: | Status: new
Cleanup/optimization |

Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by iamsteadman):

* owner: iamsteadman =>
* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/24859#comment:9>

Django

unread,
Jun 6, 2015, 7:49:34 PM6/6/15
to django-...@googlegroups.com
#24859: UUIDField does not validate query value
-------------------------------------+-------------------------------------
Reporter: cancan101 | Owner: Tim
Type: | Graham <timograham@…>
Cleanup/optimization | Status: closed

Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* owner: => Tim Graham <timograham@…>
* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"20ff296cb15a53b8b9517a834688e57749b43e21" 20ff296]:
{{{
#!CommitTicketReference repository=""
revision="20ff296cb15a53b8b9517a834688e57749b43e21"
Fixed #24859 -- Made QuerySet.get() with UUIDField raise TypeError on bad
value.

For consistency with AutoField.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24859#comment:10>

Reply all
Reply to author
Forward
0 new messages