-
Notifications
You must be signed in to change notification settings - Fork 209
[fix] Attribute error when trying to get bounding box from a method field value #246
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
base: master
Are you sure you want to change the base?
Changes from 4 commits
58ec8d0
1d57899
191209b
0040739
84cd642
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
LIST_SERIALIZER_KWARGS, | ||
ListSerializer, | ||
ModelSerializer, | ||
SerializerMethodField, | ||
) | ||
|
||
from .fields import GeometryField, GeometrySerializerMethodField # noqa | ||
|
@@ -132,7 +133,12 @@ def to_representation(self, instance): | |
# MUST be present in output according to GeoJSON spec | ||
field = self.fields[self.Meta.geo_field] | ||
geo_value = field.get_attribute(instance) | ||
feature["geometry"] = field.to_representation(geo_value) | ||
if isinstance(field, SerializerMethodField): | ||
method = getattr(field.parent, field.method_name) | ||
geo_value = method(instance) | ||
feature["geometry"] = field.to_representation(instance) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
yes, because in this case, the problem was that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, I don't understand then what's the purpose of calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
yes, it's not used afterwards, but what if -later- someone else needed to use it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand this. I don't want to introduce changes in a library that is used by thousands of developers lightly. Each change must be justified. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nemesisdesign it's justified. did you try to reproduce this bug? focus on the type of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nemesisdesign if you're not convinced by my solution, then please try to reproduce the bug #247 and maybe suggest a proper fix? |
||
else: | ||
feature["geometry"] = field.to_representation(geo_value) | ||
processed_fields.add(self.Meta.geo_field) | ||
|
||
# Bounding Box | ||
|
@@ -143,7 +149,11 @@ def to_representation(self, instance): | |
# otherwise it can be determined via another field | ||
elif self.Meta.bbox_geo_field: | ||
field = self.fields[self.Meta.bbox_geo_field] | ||
value = field.get_attribute(instance) | ||
if isinstance(field, SerializerMethodField): | ||
method = getattr(field.parent, field.method_name) | ||
value = method(instance) | ||
else: | ||
value = field.get_attribute(instance) | ||
feature["bbox"] = value.extent if hasattr(value, 'extent') else None | ||
processed_fields.add(self.Meta.bbox_geo_field) | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.