Django-treebeard 4.5.1

Hello!

The latest version of django-treebeard (4.5.1) gives error when publishing changes. Downgrading to django-treebeard==4.4 solved it.

Internal Server Error: /en/admin/cms/page/1/en/publish/
Traceback (most recent call last):
File “/web/servers/django/virtual/lib/python3.6/site-packages/django/core/handlers/exception.py”, line 47, in inner
response = get_response(request)
File “/web/servers/django/virtual/lib/python3.6/site-packages/django/core/handlers/base.py”, line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File “/web/servers/django/virtual/lib/python3.6/site-packages/django/utils/decorators.py”, line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File “/web/servers/django/virtual/lib/python3.6/site-packages/django/views/decorators/cache.py”, line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File “/web/servers/django/virtual/lib/python3.6/site-packages/django/contrib/admin/sites.py”, line 233, in inner
return view(request, *args, **kwargs)
File “/web/servers/django/virtual/lib/python3.6/site-packages/django/utils/decorators.py”, line 43, in _wrapper
return bound_method(*args, **kwargs)
File “/web/servers/django/virtual/lib/python3.6/site-packages/django/views/decorators/http.py”, line 40, in inner
return func(request, *args, **kwargs)
File “/usr/local/lib/python3.6/contextlib.py”, line 52, in inner
return func(*args, **kwds)
File “/web/servers/django/virtual/lib/python3.6/site-packages/cms/admin/pageadmin.py”, line 1116, in publish_page
all_published = page.publish(language)
File “/web/servers/django/virtual/lib/python3.6/site-packages/cms/models/pagemodel.py”, line 979, in publish
self._copy_contents(public_page, language)
File “/web/servers/django/virtual/lib/python3.6/site-packages/cms/models/pagemodel.py”, line 625, in _copy_contents
placeholder.copy_plugins(target_placeholder, language=language)
File “/web/servers/django/virtual/lib/python3.6/site-packages/cms/models/placeholdermodel.py”, line 577, in copy_plugins
root_plugin=root_plugin,
File “/web/servers/django/virtual/lib/python3.6/site-packages/cms/utils/plugins.py”, line 213, in copy_plugins_to_placeholder
new_plugin = CMSPlugin.add_root(instance=new_plugin)
File “/web/servers/django/virtual/lib/python3.6/site-packages/treebeard/mp_tree.py”, line 617, in add_root
return MP_AddRootHandler(cls, **kwargs).process()
File “/web/servers/django/virtual/lib/python3.6/site-packages/treebeard/mp_tree.py”, line 326, in process
raise NodeAlreadySaved("Attempted to add a tree node that is "
treebeard.exceptions.NodeAlreadySaved: Attempted to add a tree node that is already in the database

It is checked on FreeBSD 12.0 and Ubuntu 18.04 for Python versions 3.6 and 3.7.

Best
Alex

1 Like

Thx Alex.

here is the message we have pinned in our Slack (www.django-cms.org/slack)

IMPORTANT:Some of your folks who did deploys today might be seeing some crashes on their websites. The crashes are like this:

Internal Server Error: /admin/cms/page/add/NodeAlreadySaved at /admin/cms/page/add/
Attempted to add a tree node that is already in the database

or like this:

IntegrityError at /admin/cms/page/add-plugin/
duplicate key value violates unique constraint "cms_cmsplugin_path_key"
DETAIL: Key (path)=() already exists.

The reason for this issue is that there was a pull request merged and release to django-treebeard last evening that had some buggy code that caused this.

Another reason is that the version pinning on django-cms project itself was django-treebeard>=4.3 which is a bit dangerous and make it susceptible to crashes like the ones above.Thanks to quick help from @Andrew Aikman, the fix is to just pin the django-treebeard dependency to the stable version, so if you put django-treebeard>=4.3,<4.5

This will already fix the crash on your site. @Andrew Aikman is also working on a patch to get this into django-cms setup.py as well, but the above mentioned quick-fix is pretty good as well.