Closed sritchie closed 3 years ago
Actually, it looks like the issue goes deeper. This occurs with any unwrapped data structure, like this:
AptPackages = s.Or(
[str], s{
s.Optional("gpu", default=list): [str],
s.Optional("cpu", default=list): [str]
},
error=""""apt_packages" entry must be a dictionary or list, not '{}'""")
The error is triggered if any of the dicts or lists are unwrapped.
This succeeds:
AptPackages = s.Or(
s.Schema([str]),
s.Schema({
s.Optional("gpu", default=list): s.Schema([str]),
s.Optional("cpu", default=list): s.Schema([str])
}),
error=""""apt_packages" entry must be a dictionary or list, not '{}'""")
I'm not sure if this is valid Schema usage, but I wanted to drop my reproduction here just in case.
I have a schema that looks like this:
Trying to run that code throws this error:
When I trace, it looks like what's happening is that
self._error
on theOr
schema is getting set to the FILLED schema, on this line:https://github.com/keleshev/schema/blob/master/schema.py#L345
ie, when I insert
print(self._error)
there, I see:Which creates this case:
The issue's solved if I wrap the dictionary in
s.Schema
... but it might be worth havingOr
,And
etc do the wrapping for us if it sees a raw dict to prevent this issue.Hope this helps!