Skip to content

Commit

Permalink
refactor: check for keys and values simple types while de-serializing
Browse files Browse the repository at this point in the history
  • Loading branch information
mariajgrimaldi committed Jan 10, 2025
1 parent 2980a93 commit 7eabdaa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion openedx_events/event_bus/avro/deserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _deserialized_avro_record_dict_to_object(data: dict, data_type, deserializer
"Dict without annotation type is not supported. The argument should be a type, for eg., Dict[str, int]"
)
# Check whether dict items type is in basic types.
if arg_data_type[1] in SIMPLE_PYTHON_TYPE_TO_AVRO_MAPPING:
if all(arg in SIMPLE_PYTHON_TYPE_TO_AVRO_MAPPING for arg in arg_data_type):
return data
elif hasattr(data_type, "__attrs_attrs__"):
transformed = {}
Expand Down
7 changes: 7 additions & 0 deletions openedx_events/event_bus/avro/tests/test_deserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,13 @@ def test_deserialization_of_dict_with_complex_types_fails(self):
with self.assertRaises(TypeError):
deserializer.from_dict(initial_dict)

def test_deserialization_of_dicts_with_keys_of_complex_types_fails(self):
SIGNAL = create_simple_signal({"dict_input": Dict[CourseKey, int]})
deserializer = AvroSignalDeserializer(SIGNAL)
initial_dict = {"dict_input": {CourseKey.from_string("course-v1:edX+DemoX.1+2014"): 1}}
with self.assertRaises(TypeError):
deserializer.from_dict(initial_dict)

def test_deserialization_of_nested_list_fails(self):
"""
Check that deserialization raises error when nested list data is passed.
Expand Down

0 comments on commit 7eabdaa

Please sign in to comment.