Skip to content

fix: AttributeError CMSPlugin (EditorNotePlugin) object has no attribute config #280

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

Merged
merged 1 commit into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions djangocms_frontend/ui_plugin_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.utils.encoding import force_str

from djangocms_frontend.helpers import get_related
from djangocms_frontend.models import AbstractFrontendUIItem

try:
from cms.admin.placeholderadmin import PlaceholderAdmin
Expand Down Expand Up @@ -30,12 +31,13 @@ def __str__(self):
return force_str(super().__str__())

def render(self, context, instance, placeholder):
for key, value in instance.config.items():
if isinstance(value, dict) and set(value.keys()) == {"pk", "model"}:
if key not in instance.__dir__(): # hasattr would return the value in the config dict
setattr(instance.__class__, key, get_related(key))
if "instance" not in instance.config and isinstance(instance.config, dict):
context.update(instance.config)
if isinstance(instance, AbstractFrontendUIItem):
for key, value in instance.config.items():
if isinstance(value, dict) and set(value.keys()) == {"pk", "model"}:
if key not in instance.__dir__(): # hasattr would return the value in the config dict
setattr(instance.__class__, key, get_related(key))
Comment on lines +36 to +38
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code-quality): Merge nested if conditions (merge-nested-ifs)

Suggested change
if isinstance(value, dict) and set(value.keys()) == {"pk", "model"}:
if key not in instance.__dir__(): # hasattr would return the value in the config dict
setattr(instance.__class__, key, get_related(key))
if isinstance(value, dict) and set(value.keys()) == {"pk", "model"} and key not in instance.__dir__():
setattr(instance.__class__, key, get_related(key))


ExplanationToo much nesting can make code difficult to understand, and this is especially
true in Python, where there are no brackets to help out with the delineation of
different nesting levels.

Reading deeply nested code is confusing, since you have to keep track of which
conditions relate to which levels. We therefore strive to reduce nesting where
possible, and the situation where two if conditions can be combined using
and is an easy win.

if "instance" not in instance.config and isinstance(instance.config, dict):
context.update(instance.config)
return super().render(context, instance, placeholder)

if not hasattr(PlaceholderAdmin, "edit_field"):
Expand Down
2 changes: 2 additions & 0 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@

SITE_ID = 1

STATIC_URL = "/static/"

ROOT_URLCONF = "tests.urls"

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
Expand Down
1 change: 0 additions & 1 deletion tests/utilities/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,5 @@ def test_editor_note_with_cms4(self):

with self.login_user_context(self.superuser):
response = self.client.get(endpoint)
print(response.content)
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'My private note')