You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Running the above program with cfgv 3.2.0 on Python 3.9.1 produces the following error:
Traceback (most recent call last):
File "/Users/jwodder/work/dev/tmp/cfgv-bug.py", line 17, in <module>
print(cfgv.load_from_filename(
File "/Users/jwodder/work/dev/tmp/venv/lib/python3.9/site-packages/cfgv.py", line 411, in load_from_filename
return apply_defaults(data, schema)
File "/Users/jwodder/work/dev/tmp/venv/lib/python3.9/site-packages/cfgv.py", line 381, in apply_defaults
return schema.apply_defaults(v)
File "/Users/jwodder/work/dev/tmp/venv/lib/python3.9/site-packages/cfgv.py", line 249, in apply_defaults
item.apply_default(ret)
File "/Users/jwodder/work/dev/tmp/venv/lib/python3.9/site-packages/cfgv.py", line 94, in _apply_default_optional_recurse
_apply_default_required_recurse(self, dct)
File "/Users/jwodder/work/dev/tmp/venv/lib/python3.9/site-packages/cfgv.py", line 84, in _apply_default_required_recurse
dct[self.key] = apply_defaults(dct[self.key], self.schema)
File "/Users/jwodder/work/dev/tmp/venv/lib/python3.9/site-packages/cfgv.py", line 381, in apply_defaults
return schema.apply_defaults(v)
File "/Users/jwodder/work/dev/tmp/venv/lib/python3.9/site-packages/cfgv.py", line 247, in apply_defaults
ret = v.copy()
AttributeError: 'NoneType' object has no attribute 'copy'
My goal is to create a field that can either be set to a Map or omitted entirely. Since there's no OptionalRecurseNoDefault, I thought that setting the field's default to None would work instead. Is the recommended way to get what I want to just set the default to an empty dict, or is there a better strategy?
The text was updated successfully, but these errors were encountered:
most of the point of this library and the defaulting is to make it so you don't have to check for presence after applying defaults -- seems odd that you would want to preserve an optional mapping as None instead of the default values for that map
@asottile In my case, the field being absent has a distinct meaning (of "do not do this thing") which differs from the field having its default values (which means "do this thing with the defaults"), which is why I want to check for field presence in the first place.
Consider the following code:
cfgv-bug.json
:Running the above program with cfgv 3.2.0 on Python 3.9.1 produces the following error:
My goal is to create a field that can either be set to a Map or omitted entirely. Since there's no
OptionalRecurseNoDefault
, I thought that setting the field's default toNone
would work instead. Is the recommended way to get what I want to just set the default to an emptydict
, or is there a better strategy?The text was updated successfully, but these errors were encountered: