drf-extra-fields
drf-extra-fields copied to clipboard
invalid GEOS Geometry index: 0 Error occurs on nullable `PointField`
The following error occurs if we have a nullable PointField
on the model:
IndexError: invalid GEOS Geometry index: 0
Model field:
checkout_position = models.PointField(geography=True, null=True, blank=True)
Serializer field:
checkout_position = PointField(required=False)
Could you please provide the request data? Seems to me that checkout_position
received a data other than None, '', [], (), {}
.
due to checkout_position
is not required field, so we never send any value like the None, '', [], (), {}
in the request if we do not need to the checkout_position
data, but if we need to the checkout_position
data, we send data like the following:
{
"id": 64,
"checkout_time": "2021-02-05T11:13:27.736",
"checkout_accuracy": 15.62,
"checkout_position": {
"longitude": 51.398247,
"latitude": 35.7225148
}
}
Hi @mohammadhasanzadeh,
When I test PointField with these serializer and data:
class PointSerializer(serializers.Serializer):
checkout_position = PointField(required=False)
data = {
"checkout_position": {
"longitude": 51.398247,
"latitude": 35.7225148
}
}
results are fine:
In [17]: serializer = PointSerializer(data=data)
In [18]: serializer.is_valid()
Out[18]: True
In [19]: serializer.validated_data
Out[19]: OrderedDict([('checkout_position', <Point object at 0x7fd6b859eb10>)])
In [21]: str(serializer.validated_data["checkout_position"])
Out[21]: 'POINT (51.398247 35.7225148)'
Can you elaborate your problem more with the data you get the error?