Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Using cms.api.add_plugin() on PlaceholderFields doesn't correctly update PluginPool #2434

mkoistinen opened this Issue Dec 28, 2013 · 3 comments


None yet
2 participants

mkoistinen commented Dec 28, 2013

This relates to v3.0.0beta3

In developing a work-around for the issue #2433, I used this code to set an initial plugin on my model’s objects’ PlaceholderFields.

--from cms.api import add_plugin--

class Scholar(models.Model):
    # Normal model declaration here...

    def save(self, *args, **kwargs):
        from cms.api import add_plugin  # DO NOT use this line except inside this method.

        if not self.pk:
            super(Scholar, self).save(*args, **kwargs)
            add_plugin(self.bio, 'TextPlugin', 'en', body="<p>Scholar biography coming soon.</p>")

        # Yes, this will perform the save again if it was the initial save.
        super(Scholar, self).save(*args, **kwargs)

And, this appeared to work from a database standpoint, but when attempting to view my handiwork on the front-end, I kept getting KeyError here: https://github.com/divio/django-cms/blob/develop/cms/plugin_pool.py#L120

Here's a full backtrace: https://gist.github.com/anonymous/750bf095a6ce5898c763

My immediate for this was to insert the line:

self.discovered = False

Directly before the above-referenced line.

I also tried adding:


Before this line: https://github.com/mkoistinen/django-cms/blob/develop/cms/api.py#L281

But then the same KeyError exception occurred when deleting the object containing the programmatically added plugin. Someone with more intimate knowledge of the plugin system should have a look at this.


mkoistinen commented Dec 28, 2013

With Ojii's help, we've tracked this down to this being a circular import issue when including from cms.api import add_plugin in my models.py. The issue disappears when I move that import into the save() method itself, where it is used.

Not sure if this should be closed or not.


czpython commented Dec 28, 2013

This was reported in #1526


mkoistinen commented Dec 28, 2013

Indeed it was. I guess I'll close this one.

@mkoistinen mkoistinen closed this Dec 28, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment