-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
fix: Allow lazy wizard initialization #8265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's GuideThis PR refactors wizard initialization to be lazy via a cached property in CMSCoreExtensions, centralizes and exposes core wizard helper functions in wizard_base, deprecates legacy helper and pool modules with warnings ahead of Django CMS 5.1, simplifies toolbar disabling logic to restore wizard availability on app-hooked pages, and updates tests to align with lazy loading and reset logic. Sequence diagram for lazy wizard access via get_entriessequenceDiagram
participant User
participant Toolbar
participant CMSCoreExtensions
participant Wizard
User->>Toolbar: Request wizard actions
Toolbar->>CMSCoreExtensions: Access wizards (via get_entries)
CMSCoreExtensions->>CMSCoreExtensions: Compute wizards (cached_property)
CMSCoreExtensions->>Wizard: Return sorted wizard instances
Toolbar->>User: Show available wizards
Class diagram for lazy wizard initialization in CMSCoreExtensionsclassDiagram
class CMSCoreExtensions {
+list lazy_wizards
+dict toolbar_enabled_models
+dict model_groupers
+list toolbar_mixins
+configure_wizards(cms_config)
+configure_toolbar_enabled_models(cms_config)
+wizards: dict[str, Wizard] <<cached_property>>
}
class Wizard {
+id
+weight
+title
+user_has_add_permission(user, page)
+get_model()
}
CMSCoreExtensions "1" o-- "*" Wizard : manages
Class diagram for new and deprecated wizard helper functionsclassDiagram
class wizard_base {
+get_entries()
+get_entry(entry_key)
+entry_choices(user, page)
}
class helpers {
+get_entries() <<deprecated>>
+get_entry(entry_key) <<deprecated>>
}
class wizard_pool {
+WizardPool <<deprecated>>
+entry_choices(user, page) <<deprecated>>
}
helpers ..> wizard_base : re-exports (deprecated)
wizard_pool ..> helpers : re-exports (deprecated)
wizard_pool ..> wizard_base : re-exports (deprecated)
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
👋 Hi there! Please remember to MERGE COMMIT pull requests from Do not SQUASH commits to preserve history for the changelog. |
@sourcery-ai review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @fsbraun - I've reviewed your changes - here's some feedback:
- The new
wizards
cached_property silently merges duplicate wizard IDs—add a conflict check or warning to prevent unintended overrides of existing entries. - Misconfigured (non-Wizard) entries are only caught when accessing
wizards
; consider validating input immediately inconfigure_wizards
to fail fast at startup. - In the
wizards
property the variable namewizard
is reused in both the comprehension and thenext
call—rename one to avoid confusion and shadowing.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `wizards` cached_property silently merges duplicate wizard IDs—add a conflict check or warning to prevent unintended overrides of existing entries.
- Misconfigured (non-Wizard) entries are only caught when accessing `wizards`; consider validating input immediately in `configure_wizards` to fail fast at startup.
- In the `wizards` property the variable name `wizard` is reused in both the comprehension and the `next` call—rename one to avoid confusion and shadowing.
## Individual Comments
### Comment 1
<location> `cms/wizards/helpers.py:7` </location>
<code_context>
- Returns a wizard object based on its :attr:`~.cms.wizards.wizard_base.Wizard.id`.
- """
- return apps.get_app_config('cms').cms_extension.wizards[entry_key]
+warnings.warn(
+ "The cms.wizards.helpers module is deprecated and will be removed in django CMS 5.1. "
+ "Use cms.wizards.wizard_base.get_entries and cms.wizards.wizard_pool.get_entry instead.",
</code_context>
<issue_to_address>
Deprecation warning message references an incorrect replacement.
'wizard_pool.get_entry' does not exist in the codebase. Please update the warning to reference only valid alternatives to avoid user confusion.
</issue_to_address>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
👋 Hi there! Please remember to MERGE COMMIT pull requests from Do not SQUASH commits to preserve history for the changelog. |
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
👋 Hi there! Please remember to MERGE COMMIT pull requests from Do not SQUASH commits to preserve history for the changelog. |
* fix: Allow lazy wizard initialization * Update cms/cms_toolbars.py Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> * Update cms/cms_config.py Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> --------- Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
* fix: Allow lazy wizard initialization * Update cms/cms_toolbars.py Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> * Update cms/cms_config.py Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> --------- Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Description
This PR fixes two issues and a chore:
RemovedInDjangoCMS51Warning
to the legacy wizard pool (deprecated since Django CMS 4.0(!))Related resources
Checklist
main
Summary by Sourcery
Enable lazy wizard initialization in the CMS to avoid database access at startup, consolidate wizard registration into a cached property, add core helper functions in wizard_base, deprecate legacy helper and pool modules with warnings, and adjust toolbar logic and tests accordingly.
New Features:
Bug Fixes:
Enhancements:
Tests:
Summary by Sourcery
Implement lazy initialization of CMS wizards to avoid database access at startup, add helper functions for wizard access, restore toolbar wizard availability on app-hooked pages, and deprecate legacy wizard helper and pool modules with warnings
New Features:
Bug Fixes:
Enhancements:
Tests: