Open WolfgangFahl opened 10 months ago
i changed the code to
# a mapping type has `.keys()` and `.values()`
# (see collections.abc)
if not isinstance(value,dict):
print("Houston we got a problem!")
ks = _decode_dict_keys(k_type, value.keys(), infer_missing)
to be able to set a breakpoint and see the culprit data- then the fix is easy - so this is more a feature request then a bug report. Making the code handle the non -dict situation would be helpful
@@ -118,15 +118,14 @@ class TestModule(Basetest):
CompetenceLevel(name="3,7 - 55%", level=2),
CompetenceLevel(name="4,0 - 50%", level=1),
]
- tree.element_names = (
- {
- "tree": "Study plan",
- "aspect": "Study area",
- "area": "Module",
- "facet": "Module element",
- "level": "Grade",
- },
- )
+ tree.element_names = {
+ "tree": "Study plan",
+ "aspect": "Study area",
+ "area": "Module",
+ "facet": "Module element",
+ "level": "Grade",
+ }
@WolfgangFahl if you can submit a PR and add some units to improve the error handling, I'd be happy to review. Otherwise, there is a bit too much context details here, if you can narrow the example down to fewer lines of code it would be great
Basically the pattern is if your yaml file is not as specified e.g. you move from a list to a dict and vice versa and then throw the wrong yaml file at the json/yaml pipeline the involved dataclasses-json might choke with one or another python arror since the code assumes perfect input. To make the code more robust it might follow Postel's law a bit more and give hints when things are wrong. Also just styling the code better for debugging would help - then one can at least set a breakpoint to find out what went wrong. I'm busy for the upcoming days but will definitely be willing to supply more details and PRs.
Description
I am generating Yaml files and rereading them using the from_dict feature of dataclasses_json
Code snippet that reproduces the issue
I am still debugging so i don't have a small example yet. The code and data that fails is below. The line that causes the problem is:
content = content_class.from_dict(data)
which calls
the YAML input is
json dump of data:
therfore IMHO needs to check the type before or when trying to decode the dict. If it's not a dict there should be a proper reaction with debug info.
Python version you are using
Python 3.10.13
Environment description
dataclasses-json==0.6.1