-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
What Red version are you using?
3.5.20
What were you trying to do?
If a config key defaults to a non-dict value (ie, that key is not a Group), storing a dict to that key causes scope.all() to error when trying to recursively fetch the default values for that dict's keys. I am only able to reproduce this issue for .all, directly accessing the key does not produce an error.
It is unclear whether this should be considered a user error (mixing Groups and Values) and should be entirely prevented or if this should be considered a bug with Config and an additional check should be added in nested_update to handle this edge case.
What did you expect to happen?
No error
What actually happened?
Traceback (most recent call last):
File "<eval command - snippet #4>", line 4, in func
return await c.all()
^^^^^^^^^^^^^
File "\redbot\core\config.py", line 307, in _get
return self.nested_update(raw, default)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "\redbot\core\config.py", line 553, in nested_update
result = self.nested_update(value, defaults.get(key, {}))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "\redbot\core\config.py", line 556, in nested_update
defaults[key] = pickle.loads(pickle.dumps(current[key], -1))
~~~~~~~~^^^^^
TypeError: 'NoneType' object does not support item assignmentHow can we reproduce this error?
Example of broken code
config.register_global(testvar=None)
await config.testvar.set({"a": 4})
return await config.all() # ErrorsExample alternative that does not break (not mixing groups and values)
config.register_global(testvar={})
await config.testvar.set({"a": 4})
return await config.all() # WorksThis issue applies to values at all depths
cconfig.register_global(testvar={"b": None})
await config.testvar.set({"a": 4, "b": {"c": 56}})
return await config.all() # ErrorsAnything else?
Found by unknown
Discussion for reference:
https://discord.com/channels/133049272517001216/160386989819035648/1467179303262486613
https://discord.com/channels/133049272517001216/171665724262055936/1467617566204891339