drf-fast-serializer icon indicating copy to clipboard operation
drf-fast-serializer copied to clipboard

Note potential for differences in output representation.

Open lovelydinosaur opened this issue 11 years ago • 1 comments

Because these optimisations don't call into the field to_representation there's potential for them to end up with differing output representations, particularly when used with ujson.

Likely areas of differing representations include:

  • date/time/datetime formats.
  • decimals, wrt output precision and also float vs string representations.
  • FileField and ImageField outputs (assume we'll get path outputs, instead of typical URLs)
  • Relationships (Havn't checked, presume you'll always get pk representations, or perhaps they don't work)
  • URL identity fields (Wont work, unless the model has a url property)
  • SerializerMethodField (Won't work)
  • Nested relationships (Won't work)

Eg.

>>> ujson.dumps({'published':datetime.datetime.now()})
'{"published":1414663411}'
>>> ujson.dumps({'total_cost':decimal.Decimal('1.23')})
'{"total_cost":1.23}'

lovelydinosaur avatar Oct 30 '14 10:10 lovelydinosaur

The implementations do call field.to_representation (see https://github.com/akaariai/drf-fast-serializer/blob/master/fast_serializer/init.py#L28). What ujson does differently is a bit out of scope for my work, but still worth pointing out in the readme.

akaariai avatar Oct 30 '14 12:10 akaariai