`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.
--
Ticket URL: <https://code.djangoproject.com/ticket/24343>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Comment (by timgraham):
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
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24343#comment:1>
Comment (by shaib):
Is there a reason why we don't test the fk by accessing it?
That is, shouldn't we be doing something like
```python
testcase.assertEqual(instance.data.pk, data)
```
?
--
Ticket URL: <https://code.djangoproject.com/ticket/24343#comment:2>
* cc: me@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/24343#comment:3>
* cc: cmawebsite@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/24343#comment:4>
Comment (by shaib):
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
[https://github.com/django/django/pull/4134 Marc's PR], following the
little [https://groups.google.com/d/msgid/django-
developers/CAFO84S4CF_qo%2BMmJ1ybUsOMfD%3DPTyVxQZy8wD3vYKC6rE5%3DDwQ%40mail.gmail.com
mailing list discussion].
--
Ticket URL: <https://code.djangoproject.com/ticket/24343#comment:5>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/24343#comment:6>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"4755f8fc25331c739a6f932cc8aba0cc9e62e352"]:
{{{
#!CommitTicketReference repository=""
revision="4755f8fc25331c739a6f932cc8aba0cc9e62e352"
Fixed #24343 -- Ensure db converters are used for foreign keys.
Joint effort between myself, Josh, Anssi and Shai.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24343#comment:7>
Comment (by Marc Tamlyn <marc.tamlyn@…>):
In [changeset:"c54d73ae01cd787315ba030da17e266c49f386b3"]:
{{{
#!CommitTicketReference repository=""
revision="c54d73ae01cd787315ba030da17e266c49f386b3"
[1.8.x] Fixed #24343 -- Ensure db converters are used for foreign keys.
Joint effort between myself, Josh, Anssi and Shai.
Conflicts:
django/db/models/query.py
tests/model_fields/models.py
Backport of 4755f8fc25331c739a6f932cc8aba0cc9e62e352 from master.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24343#comment:8>
Comment (by Tim Graham <timograham@…>):
In [changeset:"5e3463f6bcec818431f0e1f4649d6a5bd944c459" 5e3463f6]:
{{{
#!CommitTicketReference repository=""
revision="5e3463f6bcec818431f0e1f4649d6a5bd944c459"
Fixed #27595 -- Made ForeignKey.get_col() follow target chains.
Previously, foreign relationships were followed only one level deep which
prevents foreign keys to foreign keys from being resolved appropriately.
This was causing issues such as improper database value conversion for
UUIDField on SQLite because the resolved expression's output field's
internal type wasn't correct. Added tests to make sure unlikely foreign
reference cycles don't cause recursion errors.
Refs #24343.
Thanks oyooyo for the report and Wayne Merry for the investigation.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24343#comment:9>