Skip to content
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

Error when adding first RootPage with multiple locales activated #245

Closed
ghost opened this issue Nov 14, 2020 · 0 comments · Fixed by #275
Closed

Error when adding first RootPage with multiple locales activated #245

ghost opened this issue Nov 14, 2020 · 0 comments · Fixed by #275
Labels
Release blocker type:bug Something isn't working
Milestone

Comments

@ghost
Copy link

ghost commented Nov 14, 2020

Whenever I have no pages (see below image)

image

and try to add one, with multiple locales set in the locale setting

image

I get the following error:

Internal Server Error: /admin/pages/add/app_cms/pageroot/1/
Traceback (most recent call last):
  File "C:\Work\virtual_env\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "C:\Work\virtual_env\lib\site-packages\django\core\handlers\base.py", line 179, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Work\virtual_env\lib\site-packages\django\views\decorators\cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "C:\Work\virtual_env\lib\site-packages\wagtail\admin\urls\__init__.py", line 127, in wrapper
    return view_func(request, *args, **kwargs)
  File "C:\Work\virtual_env\lib\site-packages\wagtail\admin\auth.py", line 193, in decorated_view
    return view_func(request, *args, **kwargs)
  File "C:\Work\virtual_env\lib\site-packages\django\views\generic\base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "C:\Work\virtual_env\lib\site-packages\wagtail\admin\views\pages\create.py", line 96, in dispatch
    return super().dispatch(request)
  File "C:\Work\virtual_env\lib\site-packages\django\views\generic\base.py", line 98, in dispatch
    return handler(request, *args, **kwargs)
  File "C:\Work\virtual_env\lib\site-packages\wagtail\admin\views\pages\create.py", line 104, in post
    return self.form_valid(self.form)
  File "C:\Work\virtual_env\lib\site-packages\wagtail\admin\views\pages\create.py", line 110, in form_valid
    return self.publish_action()
  File "C:\Work\virtual_env\lib\site-packages\wagtail\admin\views\pages\create.py", line 151, in publish_action
    self.parent_page.add_child(instance=self.page)
  File "C:\Work\virtual_env\lib\site-packages\treebeard\mp_tree.py", line 1022, in add_child
    return MP_AddChildHandler(self, **kwargs).process()
  File "C:\Work\virtual_env\lib\site-packages\treebeard\mp_tree.py", line 389, in process
    newobj.save()
  File "C:\Users\AppData\Local\Programs\Python\Python37\lib\contextlib.py", line 74, in inner
    return func(*args, **kwds)
  File "C:\Work\virtual_env\lib\site-packages\wagtail\core\models.py", line 1005, in save
    result = super().save(**kwargs)
  File "C:\Work\virtual_env\lib\site-packages\modelcluster\models.py", line 196, in save
    super(ClusterableModel, self).save(update_fields=real_update_fields, **kwargs)
  File "C:\Work\virtual_env\lib\site-packages\django\db\models\base.py", line 754, in save
    force_update=force_update, update_fields=update_fields)
  File "C:\Work\virtual_env\lib\site-packages\django\db\models\base.py", line 803, in save_base
    update_fields=update_fields, raw=raw, using=using,
  File "C:\Work\virtual_env\lib\site-packages\django\dispatch\dispatcher.py", line 179, in send
    for receiver in self._live_receivers(sender)
  File "C:\Work\virtual_env\lib\site-packages\django\dispatch\dispatcher.py", line 179, in <listcomp>
    for receiver in self._live_receivers(sender)
  File "C:\Work\virtual_env\lib\site-packages\wagtail_localize\synctree.py", line 213, in on_page_saved
    locale, copy_parents=True, alias=True
  File "C:\Users\AppData\Local\Programs\Python\Python37\lib\contextlib.py", line 74, in inner
    return func(*args, **kwds)
  File "C:\Work\virtual_env\lib\site-packages\wagtail\core\models.py", line 2325, in copy_for_translation
    reset_translation_key=False,
  File "C:\Work\virtual_env\lib\site-packages\wagtail\core\models.py", line 2210, in create_alias
    alias = parent.add_child(instance=alias)
  File "C:\Work\virtual_env\lib\site-packages\treebeard\mp_tree.py", line 1022, in add_child
    return MP_AddChildHandler(self, **kwargs).process()
  File "C:\Work\virtual_env\lib\site-packages\treebeard\mp_tree.py", line 389, in process
    newobj.save()
  File "C:\Users\AppData\Local\Programs\Python\Python37\lib\contextlib.py", line 74, in inner
    return func(*args, **kwds)
  File "C:\Work\virtual_env\lib\site-packages\wagtail\core\models.py", line 982, in save
    self.full_clean()
  File "C:\Work\virtual_env\lib\site-packages\wagtail\core\models.py", line 948, in full_clean
    super().full_clean(*args, **kwargs)
  File "C:\Work\virtual_env\lib\site-packages\django\db\models\base.py", line 1233, in full_clean
    raise ValidationError(errors)
django.core.exceptions.ValidationError: {'path': ['Page with this Path already exists.']}

With the following Page:

class PageRoot(Page):
    subpage_types = [
        'app_cms.PageCustom',
        'app_cms.PageBlogListing',
    ]

    class Meta:
        verbose_name = _('root page')
        verbose_name_plural = _('root pages')

    def __str__(self):
        return self.title
@kaedroho kaedroho added Release blocker type:bug Something isn't working labels Dec 1, 2020
@kaedroho kaedroho added this to the First release milestone Dec 1, 2020
kaedroho added a commit that referenced this issue Dec 1, 2020
Fixes #245.

This just works around the crash by disabling the auto-creation of
homepages when a new homepage is created in a locale that is set in the
"sync from" field of another.

The problem is that Treebeard calls the post_save signal before it's set
the numchild attribute of the parent. This isn't a problem in most cases
as the translations are created underneath other parent pages. But for
homepages, we need the parent `numchild` to be up to date because
translations of homepages are created as siblings.

Without the correct numchild, Treebeard/Wagtail attempts to create those
siblings with the same path which results in a crash.
kaedroho added a commit that referenced this issue Dec 1, 2020
Fixes #245.

This just works around the crash by disabling the auto-creation of
homepages when a new homepage is created in a locale that is set in the
"sync from" field of another.

The problem is that Treebeard calls the post_save signal before it's set
the numchild attribute of the parent. This isn't a problem in most cases
as the translations are created underneath other parent pages. But for
homepages, we need the parent `numchild` to be up to date because
translations of homepages are created as siblings.

Without the correct numchild, Treebeard/Wagtail attempts to create those
siblings with the same path which results in a crash.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release blocker type:bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant