jrief / djangocms-cascade

Build Single Page Applications using the Django-CMS plugin system
MIT License
165 stars 85 forks source link

TypeError while editing SimpleWrapper #414

Closed tasosalvas closed 2 years ago

tasosalvas commented 2 years ago

Hey there,

I'm trying to upgrade a site from 0.19 and bootstrap3 (django 1.11.29, django-cms 3.5.4) to 2.3.2 and bootstrap4 (django 3.2.13, django-cms 3.10.1).

On pages using SimpleWrapper, runserver errors out when I click the hamburger menu on the top right to edit the page's structure.

Error during template rendering
In template [...]/lib/python3.7/site-packages/cms/templates/cms/toolbar/dragitem.html, error at line 50
50 <span class="cms-dragitem-text" title="{{ plugin.plugin_type }} ID: {{ plugin.pk }}"><strong>{{ plugin.get_plugin_name }}</strong> {{ plugin.get_short_description }}</span>

The last few lines of the traceback:

  File "[...]/lib/python3.7/site-packages/cmsplugin_cascade/models_base.py", line 28, in __str__
    return self.plugin_class.get_identifier(self)
  File "[...]/lib/python3.7/site-packages/cmsplugin_cascade/generic/simple_wrapper.py", line 34, in get_identifier
    identifier = super().get_identifier(instance)
  File "[...]/lib/python3.7/site-packages/cmsplugin_cascade/generic/mixins.py", line 72, in get_identifier
    element_id = instance.glossary['element_id'][instance.language]
TypeError: string indices must be integers

Local vars of the last line:

__class__ <class 'cmsplugin_cascade.generic.mixins.SectionMixin'>
cls        <class 'cmsplugin_cascade.generic.simple_wrapper.SimpleWrapperPlugin'>
instance  <cmsplugin_cascade.generic.simple_wrapper.SimpleWrapperPluginModel id=6602 plugin_type='SimpleWrapperPlugin' object at 0x7f58ef55d588>

On pages that don't have a SimpleWrapper already, the structure toolbar opens up normally and I can add/edit items.

It also allows me to add a SimpleWrapper, then when I click "Save" I get the same TypeError. So it also happens on new instances.

I've been going through changelogs, addressing deprecation warnings and updating settings for a couple of days now, so I may very well be missing something simple.

Uh, what else:

That line in the mixin is set up to handle KeyError, so maaaybe I'm at an edge case where it should also handle TypeError and let super deal with it? The only weird thing about the site is i18n, though. I haven't tried it or delved too deep into the codebase - my current assumption is that I'm missing something obvious.

https://github.com/jrief/djangocms-cascade/blob/0cfcd2afed935e7b58e644bf5a3bcc1808403bbf/cmsplugin_cascade/generic/mixins.py#L70-L78

That's all, I think. Thanks for reading :). I'd be sooo relieved if you could point me in the right direction.

jrief commented 2 years ago

I'm trying to upgrade a site from 0.19 and bootstrap3 (django 1.11.29, django-cms 3.5.4) to 2.3.2 and bootstrap4

Oh, this is a huge step.

From reading your question, there can be thousand of reasons why you run into these kinds of problems. They presumably aren't even related to this app. Unfortunately I can't help you here.

tasosalvas commented 2 years ago

Huh I did try changing line 73 to:

except (KeyError, TypeError):

And everything seems to work fine - I can edit wrappers, add new ones, they render just fine, no other elements seem affected.

Of course I have no idea what else that mixin might be affecting or if the cause of that exception was some misconfiguration on my part, so uh yeah, tell me what you think. I can make a PR if it actually was a bug.

jrief commented 2 years ago

Aha. So that error occurs when instance.language = None. Would be interesting to check when and why. Have you set USE_I18N = False ?

jrief commented 2 years ago

It's fixed now on HEAD.

tasosalvas commented 2 years ago

No, it's True and the whole site is in two languages.

Thanks for giving it some more thought, I replicated the problem on a fresh instance bs4demo project and I was preparing to open a new issue. It happens there as well. Python 3.7, so poetry ends up installing django 3.2.14, apart from that completely vanilla.