Non-dict default with a dict value breaks Group.all #6648

Closed
opened 2026-02-01 22:07:58 +01:00 by Flame442 · 1 comment
Flame442 commented 2026-02-01 22:07:58 +01:00 (Migrated from github.com)

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 assignment

How can we reproduce this error?

Example of broken code

config.register_global(testvar=None)
await config.testvar.set({"a": 4})
return await config.all() # Errors

Example alternative that does not break (not mixing groups and values)

config.register_global(testvar={})
await config.testvar.set({"a": 4})
return await config.all() # Works

This 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() # Errors

Anything else?

Found by unknown

Discussion for reference:
https://discord.com/channels/133049272517001216/160386989819035648/1467179303262486613
https://discord.com/channels/133049272517001216/171665724262055936/1467617566204891339

### 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? ```py 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 assignment ``` ### How can we reproduce this error? Example of broken code ```py config.register_global(testvar=None) await config.testvar.set({"a": 4}) return await config.all() # Errors ``` Example alternative that does not break (not mixing groups and values) ```py config.register_global(testvar={}) await config.testvar.set({"a": 4}) return await config.all() # Works ``` This issue applies to values at all depths ```py cconfig.register_global(testvar={"b": None}) await config.testvar.set({"a": 4, "b": {"c": 56}}) return await config.all() # Errors ``` ### Anything else? Found by unknown Discussion for reference: https://discord.com/channels/133049272517001216/160386989819035648/1467179303262486613 https://discord.com/channels/133049272517001216/171665724262055936/1467617566204891339
Jackenmen commented 2026-11-12 13:46:40 +01:00 (Migrated from github.com)

There's no good reason for this not to be allowed. Something is only considered a Group, if it has a registered default and that default is a dict. In any other case (including non-registered values when force_registration=False), it's a Value, no matter what's actually stored to it. It should therefore be safe to accept dict values being stored under keys whose default is non-dict since they never get treated as Groups.

There's no good reason for this not to be allowed. Something is only considered a `Group`, if it has a registered default and that default is a dict. In any other case (including non-registered values when `force_registration=False`), it's a `Value`, no matter what's actually stored to it. It should therefore be safe to accept dict values being stored under keys whose default is non-dict since they never get treated as `Group`s.
Sign in to join this conversation.
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot#6648
No description provided.