Skip to content

Commit

Permalink
Add 'safe' parameter to get_item_data
Browse files Browse the repository at this point in the history
  • Loading branch information
stijn-uva committed Feb 26, 2024
1 parent b98f62a commit 4b3e4ef
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion common/lib/item_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,21 @@ def __init__(self, data, message=""):
self.message = message
self.missing = [k for k in self.data if type(self.data[k]) is MissingMappedField]

def get_item_data(self):
def get_item_data(self, safe=False):
"""
Get mapped item data
:param bool safe: Replace MissingMappedFields with their default value
:return dict:
"""
data = self.data.copy()

# replace MissingMappedFields
if safe:
for field, value in data.items():
if type(value) is MissingMappedField:
data[field] = value.value

return self.data

def get_message(self):
Expand Down

0 comments on commit 4b3e4ef

Please sign in to comment.