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

DecimalField receiving django.contrib.gis.db.models.query.GeoQuerySet #64

Closed
paulocheque opened this issue Jul 7, 2015 · 4 comments
Closed

Comments

@paulocheque
Copy link

Libs:

django==1.8.2
djangorestframework==3.1.3
djangorestframework-gis==0.9.1

settings:

'COERCE_DECIMAL_TO_STRING': True

Model:

class A(models.Model):
    aaa = models.PolygonField(null=True, blank=True, srid=4326)

Serializer:

class Aserial(GeoModelSerializer):
    class Meta:
        model = A
        fields = ('aaa',)

And serializer.data returns:

  File "/Users/paulocheque/Programming/leaf-toptal/Leaf-Management-Software/env1.8/lib/python3.4/site-packages/rest_framework/serializers.py", line 622, in data
    ret = super(ListSerializer, self).data
  File "/Users/paulocheque/Programming/leaf-toptal/Leaf-Management-Software/env1.8/lib/python3.4/site-packages/rest_framework/serializers.py", line 217, in data
    self._data = self.to_representation(self.instance)
  File "/Users/paulocheque/Programming/leaf-toptal/Leaf-Management-Software/env1.8/lib/python3.4/site-packages/rest_framework/serializers.py", line 572, in to_representation
    self.child.to_representation(item) for item in iterable
  File "/Users/paulocheque/Programming/leaf-toptal/Leaf-Management-Software/env1.8/lib/python3.4/site-packages/rest_framework/serializers.py", line 572, in <listcomp>
    self.child.to_representation(item) for item in iterable
  File "/Users/paulocheque/Programming/leaf-toptal/Leaf-Management-Software/env1.8/lib/python3.4/site-packages/rest_framework/serializers.py", line 439, in to_representation
    ret[field.field_name] = field.to_representation(attribute)
  File "/Users/paulocheque/Programming/leaf-toptal/Leaf-Management-Software/env1.8/lib/python3.4/site-packages/rest_framework/serializers.py", line 439, in to_representation
    ret[field.field_name] = field.to_representation(attribute)
  File "/Users/paulocheque/Programming/leaf-toptal/Leaf-Management-Software/env1.8/lib/python3.4/site-packages/rest_framework/fields.py", line 863, in to_representation
    value = decimal.Decimal(six.text_type(value).strip())
decimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>]

I printed the value and its type and the GeometryField(allow_null=True, required=False) is receiving a django.contrib.gis.db.models.query.GeoQuerySet

@paulocheque
Copy link
Author

I am upgrading DRF from 2 to 3. I think I missed some many=True. Anyway, if it was possible to send a better exception it would be great.

@nemesifier
Copy link
Member

Hi @paulocheque, sorry I need a bit more context to understand your issue and determine if it's something that can be improved in drf-gis or not.

@paulocheque
Copy link
Author

It is a bad exception message in DRF. Sorry about the issue.

@nemesifier
Copy link
Member

thx for updating the status

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

2 participants