-
Notifications
You must be signed in to change notification settings - Fork 26
feat: Add support for upcoming django CMS 5.1 #320
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
base: master
Are you sure you want to change the base?
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts alias placeholder rendering to support the updated Django CMS 5.1 renderer API while keeping backward compatibility with the previous signature. Sequence diagram for alias placeholder rendering with Django CMS 5.1 compatibilitysequenceDiagram
participant View
participant render_alias_structure_js
participant Renderer as BaseRenderer
View->>render_alias_structure_js: call(context, renderer, obj)
loop for each placeholder in obj.placeholders
render_alias_structure_js->>Renderer: render_placeholder(ph, language=lang, obj=obj)
alt new_renderer_api_supported
Renderer-->>render_alias_structure_js: rendered_js (obj param accepted)
else old_renderer_api_only
Renderer-->>render_alias_structure_js: TypeError
render_alias_structure_js->>Renderer: render_placeholder(ph, language=lang, page=obj)
Renderer-->>render_alias_structure_js: rendered_js (page param accepted)
end
render_alias_structure_js-->>render_alias_structure_js: append rendered_js to js_parts
end
render_alias_structure_js-->>View: "\n".join(js_parts)
Flow diagram for render_alias_structure_js compatibility logicflowchart TD
A[Start render_alias_structure_js] --> B[Initialize js_parts]
B --> C[Iterate placeholders of obj]
C --> D{Placeholder exists?}
D -- No --> C
D -- Yes --> E[Set ph.is_static = True]
E --> F["Try render_placeholder(ph, language=lang, obj=obj)"]
F --> G{TypeError raised?}
G -- No --> H[Append result to js_parts]
G -- Yes --> I["Call render_placeholder(ph, language=lang, page=obj)"]
I --> H
H --> C
C -->|All placeholders processed| J[Join js_parts with newline]
J --> K[Return JS string]
K --> L[End]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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 there - I've reviewed your changes - here's some feedback:
- Catching a bare TypeError around render_placeholder risks masking real TypeErrors from inside the method; consider feature-detecting the signature (e.g. via inspection) or checking the exception message before falling back to the old call.
- To make the compatibility intent clearer, it might be helpful to add a short comment explaining that the try/except block supports both the new
objargument and the legacypageargument in different django CMS versions.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Catching a bare TypeError around render_placeholder risks masking real TypeErrors from inside the method; consider feature-detecting the signature (e.g. via inspection) or checking the exception message before falling back to the old call.
- To make the compatibility intent clearer, it might be helpful to add a short comment explaining that the try/except block supports both the new `obj` argument and the legacy `page` argument in different django CMS versions.
## Individual Comments
### Comment 1
<location> `djangocms_alias/rendering.py:84-86` </location>
<code_context>
continue
ph.is_static = True
- js_parts.append(renderer.render_placeholder(ph, language=lang, page=obj))
+ try:
+ js_parts.append(renderer.render_placeholder(ph, language=lang, obj=obj))
+ except TypeError:
+ js_parts.append(renderer.render_placeholder(ph, language=lang, page=obj))
return "\n".join(js_parts)
</code_context>
<issue_to_address>
**issue (bug_risk):** Catching a broad TypeError may mask real bugs inside render_placeholder.
`except TypeError:` here will also catch TypeErrors thrown inside `render_placeholder` (e.g. bad args, unexpected None), not only signature mismatches. That can hide real bugs and cause a silent fallback to the `page=` call.
If the goal is to support multiple `render_placeholder` signatures, prefer a narrower check (e.g. feature detection via `inspect`/version flag, or validating the exception message is about an unexpected keyword). This keeps genuine runtime TypeErrors visible instead of swallowing them.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| try: | ||
| js_parts.append(renderer.render_placeholder(ph, language=lang, obj=obj)) | ||
| except TypeError: |
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.
issue (bug_risk): Catching a broad TypeError may mask real bugs inside render_placeholder.
except TypeError: here will also catch TypeErrors thrown inside render_placeholder (e.g. bad args, unexpected None), not only signature mismatches. That can hide real bugs and cause a silent fallback to the page= call.
If the goal is to support multiple render_placeholder signatures, prefer a narrower check (e.g. feature detection via inspect/version flag, or validating the exception message is about an unexpected keyword). This keeps genuine runtime TypeErrors visible instead of swallowing them.
Updated rendering logic to accommodate changes in django CMS 5.1 and 5.0.
Description
This reflects an internal API change of Django CMS 5. Django CMS 5.1 will remove the compatibility shim.
Related resources
Checklist
Summary by Sourcery
Enhancements:
objparameter instead ofpage, with graceful fallback for older versions.