Skip to content

Commit 2b72b89

Browse files
committed
Add a warning when registering proxy plugins for fetching
1 parent cbb7515 commit 2b72b89

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ Change log
66
Next version
77
~~~~~~~~~~~~
88

9+
- Added a warning when registering a proxy plugin with the ``RegionRenderer``
10+
with ``fetch=True``. Users should only register the concrete plugin directly
11+
for fetching, otherwise duplicated plugins are very likely while rendering.
12+
913

1014
5.4 (2025-06-19)
1115
~~~~~~~~~~~~~~~~

feincms3/renderer.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ def register(
194194
stacklevel=2,
195195
)
196196

197+
if p._meta.proxy and fetch:
198+
warnings.warn(
199+
f'The plugin {p} is a proxy but is also registered with the default "fetch=True". This can cause plugins to be fetched (and rendered) twice.',
200+
stacklevel=2,
201+
)
202+
197203
self._plugins[p] = (p, renderer, subregion, marks, fetch)
198204

199205
def plugins(self, *, fetch=True):

tests/testapp/test_oldregions.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,31 @@
88
from testapp.models import HTML, Page
99

1010

11-
class Text(SimpleNamespace):
11+
class Meta:
12+
proxy = False
13+
14+
15+
class Plugin(SimpleNamespace):
16+
_meta = Meta
17+
18+
19+
class Text(Plugin):
1220
pass
1321

1422

15-
class Teaser(SimpleNamespace):
23+
class Teaser(Plugin):
1624
subregion = "teasers"
1725

1826

19-
class FAQ(SimpleNamespace):
27+
class FAQ(Plugin):
2028
subregion = "faq"
2129

2230

23-
class Command(SimpleNamespace):
31+
class Command(Plugin):
2432
subregion = ""
2533

2634

27-
class File(SimpleNamespace):
35+
class File(Plugin):
2836
pass
2937

3038

tests/testapp/test_region_renderer.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,17 +211,20 @@ def handle_section(self, plugins, context):
211211
content = self.render_section_plugins(section, plugins, context)
212212
return f"<section>{''.join(content)}</section>"
213213

214+
class Meta:
215+
proxy = False
216+
214217
class Text:
215-
pass
218+
_meta = Meta
216219

217220
class Image:
218-
pass
221+
_meta = Meta
219222

220223
class Section:
221-
pass
224+
_meta = Meta
222225

223226
class CloseSection:
224-
pass
227+
_meta = Meta
225228

226229
renderer = SectionRenderer()
227230
renderer.register([Text], "Text") # Register as list

0 commit comments

Comments
 (0)