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

Incorrect URL for translation in menu results in broken & uneditable pages. (IndexError, MultipleObjectsReturned, etc.) #774

Closed
danthedeckie opened this issue Feb 9, 2024 · 1 comment · Fixed by #775

Comments

@danthedeckie
Copy link

danthedeckie commented Feb 9, 2024

Summary

The menu item for "translate this page" from the parent of a translation alias page shows the incorrect URL, a localize/submit/page/<id>/ with the ID of the translation alias page, rather than the original page.

Trying to translate via that URL seems to break things, either producing "Spanish -> Spanish" translations, or ending up with the new page no longer being editable at all.

Including the subtree can result in even more weirdness.

Screenshots showing our setup & the URLs:

Here's what we see (note the URL) when we go to translate from the English (original) parent view (when hovering "Translate this page")

translate-from-index-engilsh

Or if you clicked "Edit" on the page in the spanish page tree, you could then go to translate it, with basically the same URL:

translate-this-page-from-edit-spanish

The page ID in the URL is the original page ID.

Here's what we see (note the URL) when doing the same from the Spanish parent page:

translate-from-index-spanish

Note that the page ID in the URL is of the translation alias page, NOT the original!


On the older version (1.5.2) of wagtail_localize that would seem to work - but then end up with Spanish > Spanish

image

and then if child-pages and subtrees got involved, it would end up crashing and getting really confused, often resulting in the pages no longer being editable (the MultipleObjectsReturned ones).

Upgrading to 1.7, things are now a bit different. You still get the different URLs, and using the URL based on the original (english) page seems to work OK.

But using the URL based on the Spanish page results in the page now no longer being editable at all:

image

Here's the traceback on that, btw:

Traceback (most recent call last):
  File "/Users/daniel/.virtualenvs/testproject/lib/python3.10/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/Users/daniel/.virtualenvs/testproject/lib/python3.10/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/daniel/.virtualenvs/testproject/lib/python3.10/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/Users/daniel/.virtualenvs/testproject/lib/python3.10/site-packages/wagtail/admin/urls/__init__.py", line 170, in wrapper
    return view_func(request, *args, **kwargs)
  File "/Users/daniel/.virtualenvs/testproject/lib/python3.10/site-packages/wagtail/admin/auth.py", line 186, in decorated_view
    response = view_func(request, *args, **kwargs)
  File "/Users/daniel/.virtualenvs/testproject/lib/python3.10/site-packages/django/views/generic/base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "/Users/daniel/.virtualenvs/testproject/lib/python3.10/site-packages/wagtail/admin/views/pages/edit.py", line 349, in dispatch
    response = self.run_hook("before_edit_page", self.request, self.page)
  File "/Users/daniel/.virtualenvs/testproject/lib/python3.10/site-packages/wagtail/admin/views/generic/mixins.py", line 28, in run_hook
    result = fn(*args, **kwargs)
  File "/Users/daniel/.virtualenvs/testproject/lib/python3.10/site-packages/wagtail_localize/wagtail_hooks.py", line 277, in before_edit_page
    return edit_translation.edit_translation(request, translation, page)
  File "/Users/daniel/.virtualenvs/testproject/lib/python3.10/site-packages/wagtail_localize/views/edit_translation.py", line 912, in edit_translation
    "source_translation": [

Exception Type: IndexError at /en/admin/pages/745/edit/
Exception Value: list index out of range
@zerolab
Copy link
Collaborator

zerolab commented Feb 9, 2024

Thank you for the detailed issue report @danthedeckie
Will try to look into it this ASAP (but may be a bit as I don't currently have any active projects using localize 🙊). As always, happy for a PR if you happen to have the time.

I suspect the issue is around https://github.com/wagtail/wagtail-localize/blob/main/wagtail_localize/wagtail_hooks.py#L150

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants