wagtail-localize icon indicating copy to clipboard operation
wagtail-localize copied to clipboard

Error when trying to edit a translated page after publishing the source page

Open Alex0jk opened this issue 4 years ago • 1 comments
trafficstars

Hey, I think I have stumbled into an issue that was mentioned in #231 or a very similar one. Opening a new issue for more visibility. This is the error I get:

Traceback (most recent call last):
  File "/work/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/work/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/work/venv/lib/python3.8/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/work/venv/lib/python3.8/site-packages/wagtail/admin/urls/__init__.py", line 127, in wrapper
    return view_func(request, *args, **kwargs)
  File "/work/venv/lib/python3.8/site-packages/wagtail/admin/auth.py", line 172, in decorated_view
    response = view_func(request, *args, **kwargs)
  File "/work/venv/lib/python3.8/site-packages/django/views/generic/base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "/work/venv/lib/python3.8/site-packages/wagtail/admin/views/pages/edit.py", line 114, in dispatch
    response = self.run_hook('before_edit_page', self.request, self.page)
  File "/work/venv/lib/python3.8/site-packages/wagtail/admin/views/generic/hooks.py", line 16, in run_hook
    result = fn(*args, **kwargs)
  File "/work/venv/lib/python3.8/site-packages/wagtail_localize/wagtail_hooks.py", line 148, in before_edit_page
    return edit_translation.edit_translation(request, translation, page)
  File "/work/venv/lib/python3.8/site-packages/wagtail_localize/views/edit_translation.py", line 508, in edit_translation
    location_info = get_segment_location_info(source_instance, tab_helper, segment.context.path)
  File "/work/venv/lib/python3.8/site-packages/wagtail_localize/views/edit_translation.py", line 331, in get_segment_location_info
    block_value = stream_blocks_by_id[block_id]
KeyError: 'ef877559-059a-4df1-b448-732e0983507d'
ERROR django.server "GET /pages/24692/edit/ HTTP/1.1" 500 159970

I think this is happening when working with a StreamField. Imagine you have a StreamField that allows adding blocks A and B into the page. If we create a page with block A and B, then translate it to any language, let say Spanish, everything works fine. We can update the translations with no problem. Then, if we go to the source page, remove block A and publish; when we try to edit the translation it throws the error. The error is solved if we sync the translations with the source page.

What I think is happening is that when the translated page is trying to get the blocks from the source by their ids, it can't find the block so it breaks.

Alex0jk avatar Jul 14 '21 21:07 Alex0jk

Hey @Alex0jk,

have you, by any chance, tested this with the more recent version of wagtail-localize? #434 changed the logic around that area of code

zerolab avatar May 09 '22 18:05 zerolab