Repository navigation
Refactor: Consolidate attachment-panel display resolution to the render-time extension (#112) - #113
Conversation
The global template extension now renders side/full-width panels for every in-scope model, standard and custom; the startup loop keeps only additional_tab tab registration, which must happen while the URLconf is still open. Removes the per-model panel extension classes and render_attachment_panel, so the display decision lives in one place (render_panel + resolve_display_preference_for_model) and can no longer drift between two paths. Custom objects stay skipped in the startup loop, keeping startup free of custom-object DB access and PLUGINS-order dependence. Renames render_custom_object_panel -> render_panel and CustomObjectAttachmentPanel -> AttachmentPanel, which now serve all models.
Point references at render_panel; replace the 'skips non-custom objects' test with cases asserting a standard in-scope model now renders, an out-of-scope one does not, and additional_tab models get no render-time panel.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
netbox_attachments/template_content.py (1)
147-169: 🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick winCache the custom-object display lookup across render-time hook calls.
custom_object_identifier()has anlru_cachekeyed by the model class, butrender_panel()also creates a separatePluginTemplateExtensioninstance per{% plugin_left_page %},{% plugin_right_page %}, and{% plugin_full_width_page %}call. Whendisplay_settingincludes any custom-object override, each call runs this lookup again beforeleft_page/right_page/full_width_pagereturn empty. Move the resolved display key/per-model preference into request-scoped state so this global extension computes it once per rendered object.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@netbox_attachments/template_content.py` around lines 147 - 169, Cache the resolved display preference in request-scoped state so render_panel() reuses one per-model result across all PluginTemplateExtension hook instances for the same rendered object. Update the path around resolve_display_preference_for_model() to read or populate that shared state before evaluating position, while preserving existing validation and empty-return behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@netbox_attachments/tests/test_template_extensions.py`:
- Around line 193-197: Add a render-call counter or mock to
test_custom_object_panel_swallows_render_errors, associate it with the
FakeExtension used by template_content.render_panel, and assert the render
method was called exactly once alongside the existing empty-string assertion.
---
Outside diff comments:
In `@netbox_attachments/template_content.py`:
- Around line 147-169: Cache the resolved display preference in request-scoped
state so render_panel() reuses one per-model result across all
PluginTemplateExtension hook instances for the same rendered object. Update the
path around resolve_display_preference_for_model() to read or populate that
shared state before evaluating position, while preserving existing validation
and empty-return behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: a95c29c0-0cb7-4b17-959f-10b584ba5960
📒 Files selected for processing (4)
CHANGELOG.mdnetbox_attachments/template_content.pynetbox_attachments/tests/test_template_extensions.pynetbox_attachments/version.py
Count render calls so the empty string is proven to come from the swallowed exception rather than an earlier gate. Addresses a CodeRabbit review note on #113.
|
Thanks @coderabbitai — both findings addressed:
@coderabbitai resolve |
|
🐇 ✅ ✏️ Learnings added
✅ Action performedComments resolved. Approval is disabled; enable |
Closes #112.
What
AttachmentPanel,models = None) now serves side/full-width panels for all in-scope models — standard and custom.additional_tabregistration — the one mode that must run while the URLconf is still open (register_model_view()).render_attachment_panel. Display logic now lives in one place:render_panel+resolve_display_preference_for_model.render_custom_object_panel→render_panelandCustomObjectAttachmentPanel→AttachmentPanel(they serve all models now).Why
Two parallel mechanisms decided "does this object get a panel, and where?" — the
display_settingbug fixed in #110 was a symptom of them drifting apart. One brain removes that whole risk class.Behavior
No user-facing change — internal consolidation. The custom-object skip in the startup loop is intentionally kept (a small refinement of the issue text): custom objects can never be
additional_tab, so skipping loses nothing, and it preserves #110's guarantee of no custom-object DB access / noPLUGINS-order dependence at startup.Verification
make testgreen — 95 passed (+2 standard-model cases);ruff format --checkandruff checkclean.netbox_custom_objects, attachments loaded first):AttachmentPanel(models=None)and zero per-model*_attachment_extensionclasses;left_pagerenders via the global panel;additional_tabmodels get no render-time panel (tab still registered);display_settingoverride;Summary by CodeRabbit
Bug Fixes
Release