#24343 closed Bug (fixed)
UUID foreign key accessor returns inconsistent type
| Reported by: | Tim Graham | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 1.8alpha1 |
| Severity: | Release blocker | Keywords: | |
| Cc: | me@…, cmawebsite@… | Triage Stage: | Accepted |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Current test failure on Oracle (and it's an issue on other backends but tests are skipped on other backends besides Oracle and PostgreSQL due to @skipUnlessDBFeature("can_defer_constraint_checks"):
Traceback (most recent call last):
File "/mnt/jenkinsdata/workspace/django-oracle/database/oracle11/python/python2.7/django/utils/functional.py", line 15, in _curried
return _curried_func(*(args + moreargs), **dict(kwargs, **morekwargs))
File "/mnt/jenkinsdata/workspace/django-oracle/database/oracle11/python/python2.7/tests/serializers_regress/tests.py", line 479, in serializerTest
func[1](self, pk, klass, datum)
File "/mnt/jenkinsdata/workspace/django-oracle/database/oracle11/python/python2.7/tests/serializers_regress/tests.py", line 154, in fk_compare
testcase.assertEqual(data, instance.data_id)
AssertionError: UUID('3f57e641-c3c7-4990-be67-f3207e4f5bd2') != u'3f57e641c3c74990be67f3207e4f5bd2'
Give this model:
class FKToUUID(models.Model):
data = models.ForeignKey(UUIDData)
obj.data_id returns a string on all backends except PostgreSQL which returns a UUID. Might be related to the has_native_uuid_field database features flag.
Change History (9)
comment:1 by , 11 years ago
comment:2 by , 11 years ago
Is there a reason why we don't test the fk by accessing it?
That is, shouldn't we be doing something like
testcase.assertEqual(instance.data.pk, data)
?
comment:3 by , 11 years ago
| Cc: | added |
|---|
comment:4 by , 11 years ago
| Cc: | added |
|---|
comment:5 by , 11 years ago
For the people following this ticket: My suggestion above does not work, and is in the wrong direction. What appears to be the right direction is Marc's PR, following the little mailing list discussion.
comment:6 by , 11 years ago
| Has patch: | set |
|---|
comment:7 by , 11 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
If the current behavior is correct, here's a patch to simply make the test pass:
diff --git a/tests/serializers_regress/tests.py b/tests/serializers_regress/tests.py index e98a721..de2c0fc 100644 --- a/tests/serializers_regress/tests.py +++ b/tests/serializers_regress/tests.py @@ -151,6 +151,8 @@ def generic_compare(testcase, pk, klass, data): def fk_compare(testcase, pk, klass, data): instance = klass.objects.get(id=pk) + if isinstance(data, uuid.UUID) and not connection.features.has_native_uuid_field: + data = str(data).replace('-', '') testcase.assertEqual(data, instance.data_id