-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AttributeError: 'list' object has no attribute 'keys' #507
Comments
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
|
@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
The text was updated successfully, but these errors were encountered: