Skip to content

Updated ObjectField to allow for unmapped keys #302

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

Merged
merged 6 commits into from
Feb 15, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion django_elasticsearch_dsl/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ def _get_inner_field_data(self, obj, field_value_to_ignore=None):
obj, field_value_to_ignore
)

if not data and obj and isinstance(obj, dict):
data = obj

return data

def get_value_from_instance(self, instance, field_value_to_ignore=None):
Expand All @@ -125,7 +128,7 @@ def get_value_from_instance(self, instance, field_value_to_ignore=None):
if objs is None:
return {}
try:
is_iterable = bool(iter(objs))
is_iterable = bool(iter(objs)) and not isinstance(objs, dict)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think rather than changing is_iterable, change to if is_iterable and not isinstance(objs, dict): below.

except TypeError:
is_iterable = False

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like this.

Suggested change
if is_iterable and not isinstance(objs, dict)::
....

Expand Down