Skip to content

Commit

Permalink
Ensured that appropriate default data was serialized for missing fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaddison committed Sep 19, 2018
1 parent f580928 commit 84ff87d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#### 2018-09-19 version 0.1.4

* Ensured that appropriate default data was serialized for missing fields.

#### 2018-09-18 version 0.1.3

* Doc updates, bug fix (random empty logger.info call).
Expand Down
2 changes: 1 addition & 1 deletion esdocs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import logging

__appname__ = __package__
__version__ = "0.1.3"
__version__ = "0.1.4"

app_version = "{}/{}".format(__appname__, __version__)

Expand Down
6 changes: 4 additions & 2 deletions esdocs/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def serialize(cls, obj, source=None):

data = {}
for name, field in cls.doc_fields.items():
empty = False
try:
# first attempt user-defined method of manual serialization
v = getattr(cls, 'serialize_{}'.format(name))(obj, source)
Expand All @@ -122,7 +123,8 @@ def serialize(cls, obj, source=None):
try:
v = cls.get_value(obj, name, source)
except InvalidFieldLookup:
continue
v = field.empty()
empty = True

if callable(v):
v = v()
Expand All @@ -131,7 +133,7 @@ def serialize(cls, obj, source=None):
v = cls.normalize_value(v)
v = cls.adjust_value(name, v)

if v is not None:
if not empty and v is not None:
# if the field is an Object or Nested inner doc, the user will have
# defined an InnerDoc Mapper; if a related Serializer exists, it will
# be used to populate data
Expand Down

0 comments on commit 84ff87d

Please sign in to comment.