[V3 Core] Difficulty reloading a cog with multiple modules. #1457
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#1457
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?
Please be sure to read through other issues as well to make sure what you are suggesting/reporting has not already
been suggested/reported
Type:
Brief description of the problem
Reloading a cog seems to only work with the main module. Auxiliary module changes do not appear to be reflected in the reload. Workaround involves doing a bot shutdown and starting the bot again.
Expected behavior
The cog and all supporting modules in the folder are "reloaded" to reflect the changes.
Actual behavior
Only changes made to the main cog are reflected in the main cog. Shutting down the bot and starting it again is the only way to see the changes.
Steps to reproduce
This is a pretty complex issue unfortunately, and something lots of projects have trouble with. Here's an example of why.
We have a python package:
Say we make some modifications to the code in some of these modules, and want to reload it. Obviously, only one module can be interpreted at a time. So which one do we do first? It begs the question. What the
reloadcommand does is iterates over each module inside the package, reloading one after the other.For now let's assume we're reloading
__init__.pyfirst.Say inside
__init__.py, we have this import line:So from here, python will go and look for whatever needs to be imported from
module1.py. However, it's doing this before we have a chance to reloadmodule1.py, hence whatever is imported will be from the old module.The same thing will happen when we reload
module1.py, if it depends in any way onmodule2.py.Reloading a module after a separate module has already imported an object from it obviously will not change the behaviour of that imported object.
In summary
This issue is dependent on the import order of the modules within your package. Sometimes, reloading will show the changes, sometimes it won't.
To solve this issue, we need to recursively reload modules which are imported from within other modules. However this recursion isn't particularly reliable if two modules import each other. You've struck gold on this one, RJM :)
Should be mostly fixed with #1458, closing for now. If this issue pops up again we'll need another issue with more detail on that specific case.