Fixed #24320 - Used field.value_to_string() in serialization of foreign key.
This fixes serialization of a ForeignKey to a UUIDField as the test indicates.
This commit is contained in:
parent
b4caa91c8b
commit
5c995dcfc2
|
@ -63,6 +63,8 @@ class Serializer(base.Serializer):
|
||||||
value = None
|
value = None
|
||||||
else:
|
else:
|
||||||
value = getattr(obj, field.get_attname())
|
value = getattr(obj, field.get_attname())
|
||||||
|
if not is_protected_type(value):
|
||||||
|
value = field.value_to_string(obj)
|
||||||
self._current[field.name] = value
|
self._current[field.name] = value
|
||||||
|
|
||||||
def handle_m2m_field(self, obj, field):
|
def handle_m2m_field(self, obj, field):
|
||||||
|
|
|
@ -276,6 +276,10 @@ class UUIDData(models.Model):
|
||||||
data = models.UUIDField(primary_key=True)
|
data = models.UUIDField(primary_key=True)
|
||||||
|
|
||||||
|
|
||||||
|
class FKToUUID(models.Model):
|
||||||
|
data = models.ForeignKey(UUIDData)
|
||||||
|
|
||||||
|
|
||||||
class ComplexModel(models.Model):
|
class ComplexModel(models.Model):
|
||||||
field1 = models.CharField(max_length=10)
|
field1 = models.CharField(max_length=10)
|
||||||
field2 = models.CharField(max_length=10)
|
field2 = models.CharField(max_length=10)
|
||||||
|
|
|
@ -28,15 +28,15 @@ from .models import (
|
||||||
BooleanData, BooleanPKData, CharData, CharPKData, ComplexModel, DateData,
|
BooleanData, BooleanPKData, CharData, CharPKData, ComplexModel, DateData,
|
||||||
DateTimeData, DecimalData, DecimalPKData, EmailData, EmailPKData,
|
DateTimeData, DecimalData, DecimalPKData, EmailData, EmailPKData,
|
||||||
ExplicitInheritBaseModel, FileData, FilePathData, FilePathPKData, FKData,
|
ExplicitInheritBaseModel, FileData, FilePathData, FilePathPKData, FKData,
|
||||||
FKDataNaturalKey, FKDataToField, FKDataToO2O, FKSelfData, FloatData,
|
FKDataNaturalKey, FKDataToField, FKDataToO2O, FKSelfData, FKToUUID,
|
||||||
FloatPKData, GenericData, GenericIPAddressData, GenericIPAddressPKData,
|
FloatData, FloatPKData, GenericData, GenericIPAddressData,
|
||||||
InheritAbstractModel, InheritBaseModel, IntegerData, IntegerPKData,
|
GenericIPAddressPKData, InheritAbstractModel, InheritBaseModel,
|
||||||
Intermediate, LengthModel, M2MData, M2MIntermediateData, M2MSelfData,
|
IntegerData, IntegerPKData, Intermediate, LengthModel, M2MData,
|
||||||
ModifyingSaveData, NaturalKeyAnchor, NullBooleanData, O2OData,
|
M2MIntermediateData, M2MSelfData, ModifyingSaveData, NaturalKeyAnchor,
|
||||||
PositiveIntegerData, PositiveIntegerPKData, PositiveSmallIntegerData,
|
NullBooleanData, O2OData, PositiveIntegerData, PositiveIntegerPKData,
|
||||||
PositiveSmallIntegerPKData, ProxyBaseModel, ProxyProxyBaseModel, SlugData,
|
PositiveSmallIntegerData, PositiveSmallIntegerPKData, ProxyBaseModel,
|
||||||
SlugPKData, SmallData, SmallPKData, Tag, TextData, TimeData, UniqueAnchor,
|
ProxyProxyBaseModel, SlugData, SlugPKData, SmallData, SmallPKData, Tag,
|
||||||
UUIDData,
|
TextData, TimeData, UniqueAnchor, UUIDData,
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -201,6 +201,7 @@ im_obj = (im_create, im_compare)
|
||||||
o2o_obj = (o2o_create, o2o_compare)
|
o2o_obj = (o2o_create, o2o_compare)
|
||||||
pk_obj = (pk_create, pk_compare)
|
pk_obj = (pk_create, pk_compare)
|
||||||
inherited_obj = (inherited_create, inherited_compare)
|
inherited_obj = (inherited_create, inherited_compare)
|
||||||
|
uuid_obj = uuid.uuid4()
|
||||||
|
|
||||||
test_data = [
|
test_data = [
|
||||||
# Format: (data type, PK value, Model Class, data)
|
# Format: (data type, PK value, Model Class, data)
|
||||||
|
@ -356,7 +357,8 @@ The end."""),
|
||||||
# The end."""),
|
# The end."""),
|
||||||
# (pk_obj, 770, TimePKData, datetime.time(10, 42, 37)),
|
# (pk_obj, 770, TimePKData, datetime.time(10, 42, 37)),
|
||||||
# (pk_obj, 790, XMLPKData, "<foo></foo>"),
|
# (pk_obj, 790, XMLPKData, "<foo></foo>"),
|
||||||
(pk_obj, 791, UUIDData, uuid.uuid4()),
|
(pk_obj, 791, UUIDData, uuid_obj),
|
||||||
|
(fk_obj, 792, FKToUUID, uuid_obj),
|
||||||
|
|
||||||
(data_obj, 800, AutoNowDateTimeData, datetime.datetime(2006, 6, 16, 10, 42, 37)),
|
(data_obj, 800, AutoNowDateTimeData, datetime.datetime(2006, 6, 16, 10, 42, 37)),
|
||||||
(data_obj, 810, ModifyingSaveData, 42),
|
(data_obj, 810, ModifyingSaveData, 42),
|
||||||
|
|
Loading…
Reference in New Issue