Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invalid GEOS Geometry index: 0 Error occurs on nullable PointField #151

Open
mohammadhasanzadeh opened this issue Jan 20, 2021 · 3 comments

Comments

@mohammadhasanzadeh
Copy link

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)

@alicertel
Copy link
Contributor

Could you please provide the request data? Seems to me that checkout_position received a data other than None, '', [], (), {}.

@mohammadhasanzadeh
Copy link
Author

mohammadhasanzadeh commented Feb 5, 2021

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
    }
}

@KaratasFurkan
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants