Patch TemplateProxy to restore compatibility with template_partials #1328
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements TemplateProxy patching to restore compatibility between django-components and template_partials, as suggested by @carltongibson in issue #1323.
Problem
When both
django-components
andtemplate_partials
are used together, theTemplateProxy
class from template_partials doesn't receive the same monkey-patching that django-components applies to Django'sTemplate
class. This can lead to compatibility issues with component context handling and dependency rendering.Solution
The fix adds conditional patching of
TemplateProxy
whentemplate_partials
is detected inINSTALLED_APPS
:Enhanced monkey-patching system: Added
monkeypatch_template_proxy_cls()
andmonkeypatch_template_proxy_render()
functions that apply the same context handling and dependency rendering logic toTemplateProxy
as is applied to Django'sTemplate
class.Conditional activation: Modified
ComponentsConfig.ready()
to check for"template_partials"
insettings.INSTALLED_APPS
and automatically patchTemplateProxy
if present.Safe error handling: The implementation gracefully handles cases where
template_partials
is listed inINSTALLED_APPS
but not actually installed.Key Features
Example Usage
The patching ensures that template partials work correctly within component contexts and that any CSS/JS dependencies are properly rendered.
Fixes #1327.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.