Closed
Description
When trying to serialize a GeometryField that contains an empty Point, the serialization fails with the following trace:
File "/usr/local/lib/python3.6/site-packages/rest_framework/serializers.py" in to_representation
527. ret[field.field_name] = field.to_representation(attribute)
File "/usr/local/lib/python3.6/site-packages/rest_framework_gis/fields.py" in to_representation
31. geojson = GeoJsonDict(value.geojson)
File "/usr/local/lib/python3.6/site-packages/rest_framework_gis/fields.py" in __init__
126. super(GeoJsonDict, self).__init__(*args, **kwargs)
Here's the geometry Point object in question:
>>> geometry
<Point object at 0x7f2da4334450>
>>> geometry.wkt
'POINT EMPTY'
>>> geometry.json
Using
django==2.0.7
djangorestframework==3.8.2
djangorestframework-gis==0.13.0
How to reproduce
from django.contrib.gis.geos import Point
from rest_framework.serializers import Serializer
from rest_framework_gis.fields import GeometryField
class MySerializer(Serializer):
geometry = GeometryField()
p = Point()
instance = {'geometry': p}
my_serializer = MySerializer()
my_serializer.to_representation(instance)