Test implicit subclass type conversion in config defaults/sets #5874
No reviewers
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 project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Mrcoolgamer11/Red-DiscordBot!5874
Loading…
Reference in a new issue
No description provided.
Delete branch "test-cast-subclass-defaults"
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?
Description of the changes
#5557 modified config to enforce JSON serializability in defaults, as before this change non-serializable objects could be used as defaults but could not be passed to config set methods (ref). As #5585 points out, this change caused a previous "feature" of config defaults passing serializable data to subclasses of equivalent python builtins to stop working. Due to numerous gotchas associated with that "feature" (ref), restoring it is not something we are looking to support.
Our current method of serializing data accepts subclasses as inputs and implicitly converts them to their respective JSON serializable type, but always returns a basic builtin as its output. This PR adds a test to explicitly test this functionality, so similar unintended consequences of a simple change do not break expected behavior without it being acknowledged, as #5557 did.
Supersedes / Closes #5585
Have the changes in this PR been tested?
Yes, confirmed that reverting
github.com/Cog-Creators/Red-DiscordBot@b0ab6186efcauses this test to fail:The test passes on the latest commit.
Is there a reason for this import not to be at the top?
@ -596,0 +602,4 @@assert config.defaults["GLOBAL"]["foo"] == {}stored_value = await config.foo()assert type(stored_value) is dictassert stored_value == {}I think an issue reference for more context would make sense here:
@ -596,0 +604,4 @@assert type(stored_value) is dictassert stored_value == {}await config.foo.set(Counter({"bar": 1}))stored_value = await config.foo()I think we should assert that the value stored in
defaultsis not a Counter instance as well.github.com/Cog-Creators/Red-DiscordBot@233278053b/tests/cogs/test_mod.py (L14-L15)I saw imports that are used for a test imported in that test in other places. I assumed since it was used like that elsewhere, that it might need to be like that, but if it should be at the top of the file I can put it there instead.
It looks like a code-style thing but we're not consistent about it at all (for comparison, see Downloader, Trivia, or any core tests which put imports at the top). Let's put the import at the top!
Looks good.