Django-treebeard 4.5.1


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/”, line 47, in inner
response = get_response(request)
File “/web/servers/django/virtual/lib/python3.6/site-packages/django/core/handlers/”, 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/”, line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File “/web/servers/django/virtual/lib/python3.6/site-packages/django/views/decorators/”, 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/”, line 233, in inner
return view(request, *args, **kwargs)
File “/web/servers/django/virtual/lib/python3.6/site-packages/django/utils/”, line 43, in _wrapper
return bound_method(*args, **kwargs)
File “/web/servers/django/virtual/lib/python3.6/site-packages/django/views/decorators/”, line 40, in inner
return func(request, *args, **kwargs)
File “/usr/local/lib/python3.6/”, line 52, in inner
return func(*args, **kwds)
File “/web/servers/django/virtual/lib/python3.6/site-packages/cms/admin/”, line 1116, in publish_page
all_published = page.publish(language)
File “/web/servers/django/virtual/lib/python3.6/site-packages/cms/models/”, line 979, in publish
self._copy_contents(public_page, language)
File “/web/servers/django/virtual/lib/python3.6/site-packages/cms/models/”, line 625, in _copy_contents
placeholder.copy_plugins(target_placeholder, language=language)
File “/web/servers/django/virtual/lib/python3.6/site-packages/cms/models/”, line 577, in copy_plugins
File “/web/servers/django/virtual/lib/python3.6/site-packages/cms/utils/”, 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/”, line 617, in add_root
return MP_AddRootHandler(cls, **kwargs).process()
File “/web/servers/django/virtual/lib/python3.6/site-packages/treebeard/”, 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.


1 Like

Thx Alex.

here is the message we have pinned in our 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 as well, but the above mentioned quick-fix is pretty good as well.