Config defaults not actually updating after a cog reload #5805
Labels
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
No due date set.
Dependencies
No dependencies set
Reference
Mrcoolgamer11/Red-DiscordBot#5805
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What Red version are you using?
3.4.16
What were you trying to do?
Updating guild defaults for Config in my cog.
What did you expect to happen?
For the new defaults to be returned when
.all()is called on a Group object.What actually happened?
Old defaults being returned instead.
How can we reproduce this error?
.clear()on a Group.Anything else?
No response
EDIT: Misread the report, see followup comment which actually addresses the real issue.
I believe this is intended behavior. Config does not have an option to remove defaults, only to add new defaults or to override current ones. As such, successive
register_scopecalls will add the provided keys (if they did not exist), and will override the current default (if they did exist) for each key. There is no way (I can see, through the public APIs) to remove a default once it has been set without creating a new Config object.Through my testing, this behavior is correct:
When keys are added, they become functional, and have the new default (
bazin the following example).When keys are overridden, a
clearcauses the new default to be used instead of the old one (fooin the following example).When keys are not included, they are not "removed", they just do not get changed. The old default continues to be used (
barin the following example).If you are seeing different behavior, please provide a code sample to reproduce the behavior you are describing, as your reproduction steps do not have any specific lines of code used beyond
.clear(). If your issue matches with this intended behavior and you want to make a feature request to add a way to remove existing defaults during the life of a Config option, please make a new issue requesting that instead.Code (Hidden, as it is not relevant to the actual bug report, see followup comment)
Code I used to attempt to reproduce your issue (this is code suited for a testing eval, not code that should be considered at all reasonable to use in production)
Output
So it looks like I missed the "reload" part of your original report - my bad. Updated code snippet below, which includes a simulated "reload", showing that creating a new Config object properly clears defaults (when used correctly).
The behavior is still consistent with what it should be in this case as well:
When keys are added, they become functional, and have the new default (baz in the following example).
When keys are overridden, a clear causes the new default to be used instead of the old one (foo in the following example).
When keys are not included, the default is "removed", but internally the current value (NOT the default) does not get changed If that key is registered later, it will still have the old value. However, attempting to get the value after clearing while it has not been registered for the current Config object will either raise an exception if
force_registration=True, or will return the base default ofNone(bar in the following example).Again, if this behavior is not what you expect for any reason, feel free to comment with a code snippet and an explanation of what you believe should be happening.
Output
Due to not receiving a response, and this seeming like intended behavior, I'm closing this issue. If you still think there is an issue, and you can provide exact reproduction steps similar to what I wrote, I can take another look at this.