Skip to content

Commit

Permalink
Fixing bug that prevented to store False used/generated values
Browse files Browse the repository at this point in the history
  • Loading branch information
renan-souza committed Sep 23, 2023
1 parent fb7bf45 commit b349e95
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
9 changes: 6 additions & 3 deletions flowcept/flowceptor/consumers/consumer_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ def curate_task_msg(task_msg_dict: dict):
if field not in task_msg_dict:
continue
field_val = task_msg_dict[field]
if not field_val:
if type(field_val) == dict and not field_val:
task_msg_dict.pop(field) # removing empty fields
continue
if type(field_val) == dict:
original_field_val = field_val.copy()
for k in original_field_val:
if not original_field_val[k]:
if (
type(original_field_val[k]) == dict
and not original_field_val[k]
):
field_val.pop(k) # removing inner empty fields
task_msg_dict[field] = field_val
else:
Expand All @@ -35,7 +38,7 @@ def remove_empty_fields_from_dict(obj: dict):
for key, value in list(obj.items()):
if isinstance(value, dict):
remove_empty_fields_from_dict(value)
if not value:
if value is None:
del obj[key]
elif value in (None, ""):
del obj[key]
Expand Down
3 changes: 2 additions & 1 deletion tests/doc_db_inserter/doc_db_inserter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def test_db_insert_and_update_many(self):
"myid": uid,
"debug": True,
"name": "Renan2",
"used": {"bla": 2},
"empty_string": "",
"used": {"bla": 2, "lala": False},
},
]
self.doc_dao.insert_and_update_many("myid", docs)
Expand Down
2 changes: 2 additions & 0 deletions tests/plugins/test_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ def test_map_workflow_kwargs(self):
i1 = [
{"x": np.random.random(), "y": np.random.random()},
{"x": np.random.random()},
{"x": 4, "batch_norm": False},
{"x": 6, "batch_norm": True, "empty_string": ""},
]
wf_id = f"wf_{uuid4()}"
o1 = TestDask.client.map(dummy_func4, i1, workflow_id=wf_id)
Expand Down

0 comments on commit b349e95

Please sign in to comment.