wagtail / wagtail-localize

Translation plugin for Wagtail CMS
https://wagtail-localize.org/
Other
222 stars 84 forks source link

I'm no longer able to make translations - [object] matching query does not exist #591

Open enzedonline opened 2 years ago

enzedonline commented 2 years ago

[object ] will be the page model

This is happening on my dev site, I don't have a second locale on the live site enabled yet. When I came across this earlier, I checked existing translations were ok and could be sync'd - everything fine there. I decided to delete all the objects in the translated locale, delete the locale in the admin interface and start over. Now I can only translate as far down as the home page, anything below throws this error.

When I look at the last calls before the exception, the variables look ok:

.venv\lib\site-packages\wagtail_localize\views\submit_translations.py, line 175, in dispatch
        return super().dispatch(request, *args, **kwargs) …
Local vars
Variable    Value
__class__   <class 'wagtail_localize.views.submit_translations.SubmitTranslationView'>
args        ()
kwargs      {'page_id': 41}
request     <WSGIRequest: POST '/admin/localize/submit/page/41/'>
self        <wagtail_localize.views.submit_translations.SubmitPageTranslationView object at 0x0000027AAFF9F220>

.venv\lib\site-packages\wagtail_localize\views\submit_translations.py, line 119, in post
            return self.form_valid(form) …
Local vars  
Variable    Value
form        <SubmitTranslationForm bound=True, valid=True, fields=(select_all;locales;include_subtree)>
kwargs      {'page_id': 41}
request     <WSGIRequest: POST '/admin/localize/submit/page/41/'>
self        <wagtail_localize.views.submit_translations.SubmitPageTranslationView object at 0x0000027AAFF9F220>

Python39\lib\contextlib.py, line 79, in inner
                return func(*args, **kwds) …
Local vars
Variable    Value
args        (<wagtail_localize.views.submit_translations.SubmitPageTranslationView object at 0x0000027AAFF9F220>,
 <SubmitTranslationForm bound=True, valid=True, fields=(select_all;locales;include_subtree)>)
func        <function SubmitTranslationView.form_valid at 0x0000027AFE029940>
kwds        {}
self        <django.db.transaction.Atomic object at 0x0000027AFE02E6A0>

.venv\lib\site-packages\wagtail_localize\views\submit_translations.py, line 151, in form_valid
            single_translated_object = self.object.get_translation( …
Local vars
Variable    Value
form        <SubmitTranslationForm bound=True, valid=True, fields=(select_all;locales;include_subtree)>
locales     'Spanish'
self        <wagtail_localize.views.submit_translations.SubmitPageTranslationView object at 0x0000027AAFF9F220>
single_translated_object    None

.venv\lib\site-packages\wagtail\models\i18n.py, line 165, in get_translation
        return self.get_translations(inclusive=True).get(locale_id=pk(locale)) …
Local vars
Variable    Value
locale      <Locale: Spanish>
self        <ServicePage: Test Document>

.venv\lib\site-packages\django\db\models\query.py, line 439, in get
            raise self.model.DoesNotExist( …
Local vars
Variable    Value
args        ()
clone       <PageQuerySet []>
kwargs      {'locale_id': 4}
limit       21
num     0
self        <PageQuerySet [<ServicePage: Test Document>]>

Exception Type: DoesNotExist at /admin/localize/submit/page/41/
Exception Value: ServicePage matching query does not exist.

Page 41 is the correct ID for the page I'm trying to translate in this case.

One model has a snippet. That throws a similar error but that it can't find the snippet instance which I guess is related but hits before submitting the page as above.

.venv\lib\site-packages\django\contrib\contenttypes\models.py, line 175, in get_object_for_this_type
        return self.model_class()._base_manager.using(self._state.db).get(**kwargs) …
Local vars
Variable    Value
kwargs      {'locale_id': 1, 'translation_key': UUID('e3c455f3-2cab-47e5-abf3-c8c3586c5534')}
self        <ContentType: site_settings | Email Signature>

Exception Type: DoesNotExist at /admin/localize/submit/page/16/
Exception Value: EmailSignature matching query does not exist.

I've tried this with both translated and untranslated snippet, same result.

Stepping through to see if I could pick up anything, it seems the error is thrown in wagtail.admin.auth.require_admin_access

                with LogContext(user=user):
                    if preferred_language:
                        ...
                    else:
                        return view_func(request, *args, **kwargs)

This last line throws a PermissionDenied error, which doesn't make sense as I'm logged in with superuser account. I checked all the permissions for the account in django-admin, it's all there.

Any idea what can cause this?

Django Version: 4.0.2 Python Version: 3.9.4 Wagtail: 3.0.1 wagtail-localize: 1.2.1

zerolab commented 2 years ago

@enzedonline can you double check, is EmailSignature a site setting (which we don't yet support), or a snippet?

enzedonline commented 2 years ago

@zerolab it's a snippet:

code ```python @register_snippet class EmailSignature(TranslatableMixin, models.Model): signature_name = models.CharField( max_length=30, null=False, blank=False, verbose_name=_("Signature Name"), help_text=_("Used to identify this signature") ) signature_heading = models.CharField( max_length=50, null=False, blank=False, verbose_name=_("Heading"), help_text=_("Company/Organisation name or other heading.") ) signature_sub_heading = models.TextField( null=True, blank=True, verbose_name=_("Sub Heading"), help_text=_("Optional sub heading such as address, motto, department, title etc.") ) signature_heading_link = models.URLField( max_length=200, null=True, blank=True, verbose_name=_("Heading Link"), help_text=_("Optional hyperlink address for heading.") ) address = models.TextField( null=True, blank=True, verbose_name=_("Address"), help_text=_("Optional"), ) map_link = models.URLField( null=True, blank=True, verbose_name=_("Map Link"), help_text=_("Option link to online map (eg Google Maps)") ) map_icon = models.ForeignKey( 'wagtailimages.Image', blank=True, null=True, related_name='+', on_delete=models.SET_NULL, verbose_name=_("Map Icon"), help_text=_("Optional icon displayed alongside address @ 15x15px") ) signature_image = models.ForeignKey( 'wagtailimages.Image', blank=True, null=True, related_name='+', on_delete=models.SET_NULL, verbose_name=_("Signature Image"), help_text=_("Optional image to display in Email Signature @ 64x64px") ) contact_email_label = models.CharField( max_length=80, default=_("Email:"), verbose_name=_("Contact Email Label"), help_text=_("Label for email address displayed in footer.") ) contact_email_address = models.EmailField( max_length=80, verbose_name=_("Contact Email Address"), help_text=_("Email address displayed in footer.") ) email_icon = models.ForeignKey( 'wagtailimages.Image', blank=True, null=True, related_name='+', on_delete=models.SET_NULL, verbose_name=_("Email Icon"), help_text=_("Optional icon displayed alongside email address @ 15x15px") ) contact_phone_label = models.CharField( max_length=80, default=_("Phone:"), verbose_name=_("Contact Phone Label"), help_text=_("Label for phone number displayed in footer.") ) contact_phone_number = models.CharField( max_length=80, verbose_name=_("Contact Phone Number"), help_text=_("Phone number displayed in footer.") ) phone_icon = models.ForeignKey( 'wagtailimages.Image', blank=True, null=True, related_name='+', on_delete=models.SET_NULL, verbose_name=_("Phone Icon"), help_text=_("Optional icon displayed alongside phone number @ 15x15px") ) panels = [ FieldPanel('signature_name'), MultiFieldPanel([ FieldPanel('signature_heading'), FieldPanel('signature_sub_heading'), FieldPanel('signature_heading_link'), ], heading=_("Heading Settings")), MultiFieldPanel([ FieldPanel('address'), FieldPanel('map_link'), FieldPanel('map_icon'), ], heading=_("Address Settings")), FieldPanel('signature_image'), MultiFieldPanel([ FieldRowPanel([ FieldPanel("contact_email_label", classname='col-6'), FieldPanel("contact_email_address", classname='col-6'), ]), FieldPanel("email_icon"), ], heading=_("Contact Email Settings")), MultiFieldPanel([ FieldRowPanel([ FieldPanel("contact_phone_label", classname='col-6'), FieldPanel("contact_phone_number", classname='col-6'), ]), FieldPanel("phone_icon"), ], heading=_("Contact Phone Settings")), ] def __str__(self): """The string representation of this class""" return self.signature_name class Meta: verbose_name = _('Email Signature') verbose_name_plural = _('Email Signatures') unique_together = ('translation_key', 'locale') ```

It's only referenced in the ContactPage class, there are 3 other classes under HomePage that can't be translated also.

enzedonline commented 2 years ago

Would be good to get this resolved, still no further on understanding the cause of this and why I would get a Permission Denied error when logged in as super user - I'm thinking that's a red herring.

Stack from trying to translate a ServicePage model instance:

Traceback (most recent call last):
  File "c:\Django\enzedonline\.venv\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "c:\Django\enzedonline\.venv\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "c:\Django\enzedonline\.venv\lib\site-packages\django\views\decorators\cache.py", line 57, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "c:\Django\enzedonline\.venv\lib\site-packages\wagtail\admin\urls\__init__.py", line 161, in wrapper
    return view_func(request, *args, **kwargs)
  File "c:\Django\enzedonline\.venv\lib\site-packages\wagtail\admin\auth.py", line 182, in decorated_view
    response = view_func(request, *args, **kwargs)
  File "c:\Django\enzedonline\.venv\lib\site-packages\django\views\generic\base.py", line 69, in view
    return self.dispatch(request, *args, **kwargs)
  File "c:\Django\enzedonline\.venv\lib\site-packages\wagtail_localize\views\submit_translations.py", line 175, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "c:\Django\enzedonline\.venv\lib\site-packages\django\views\generic\base.py", line 101, in dispatch
    return handler(request, *args, **kwargs)
  File "c:\Django\enzedonline\.venv\lib\site-packages\wagtail_localize\views\submit_translations.py", line 119, in post
    return self.form_valid(form)
  File "C:\Program Files\Python310\lib\contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "c:\Django\enzedonline\.venv\lib\site-packages\wagtail_localize\views\submit_translations.py", line 151, in form_valid
    single_translated_object = self.object.get_translation(
  File "c:\Django\enzedonline\.venv\lib\site-packages\wagtail\models\i18n.py", line 165, in get_translation
    return self.get_translations(inclusive=True).get(locale_id=pk(locale))
  File "c:\Django\enzedonline\.venv\lib\site-packages\django\db\models\query.py", line 439, in get
    raise self.model.DoesNotExist(

Exception Type: DoesNotExist at /admin/localize/submit/page/41/
Exception Value: ServicePage matching query does not exist.
enzedonline commented 2 years ago

Similar issue translating snippets:

DoesNotExist at /admin/localize/submit/snippet/blog/personalblogcategory/9/
PersonalBlogCategory matching query does not exist.

Environment:

Request Method: POST
Request URL: http://localhost:8000/admin/localize/submit/snippet/blog/personalblogcategory/9/

Django Version: 4.0.2
Python Version: 3.10.6
Installed Applications:
['home',
 'search',
 'service',
 'blog',
 'menu',
 'core',
 'site_settings',
 'contact',
 'userauth',
 'adv_cache_tag',
 'rest_framework',
 'wagtailmetadata',
 'wagtailfontawesome',
 'widget_tweaks',
 'django_comments_xtd',
 'django_comments',
 'django_extensions',
 'wagtail_localize',
 'wagtail_localize.locales',
 'wagtail.contrib.forms',
 'wagtail.contrib.redirects',
 'wagtail.contrib.routable_page',
 'wagtail.contrib.modeladmin',
 'wagtail.contrib.settings',
 'wagtail.contrib.sitemaps',
 'wagtail.embeds',
 'wagtail.sites',
 'wagtail.users',
 'wagtail.snippets',
 'wagtail.documents',
 'wagtail.images',
 'wagtail.search',
 'wagtail.admin',
 'wagtail',
 'modelcluster',
 'taggit',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.sitemaps',
 'django.contrib.staticfiles',
 'django.contrib.sites',
 'allauth',
 'allauth.account',
 'allauth.socialaccount',
 'allauth.socialaccount.providers.facebook',
 'allauth.socialaccount.providers.google',
 'allauth.socialaccount.providers.linkedin_oauth2',
 'captcha',
 'wagtailcaptcha']
Installed Middleware:
['django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'wagtail.contrib.redirects.middleware.RedirectMiddleware']

Traceback (most recent call last):
  File "\.venv\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "\.venv\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "\.venv\lib\site-packages\django\views\decorators\cache.py", line 57, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "\.venv\lib\site-packages\wagtail\admin\urls\__init__.py", line 161, in wrapper
    return view_func(request, *args, **kwargs)
  File "\.venv\lib\site-packages\wagtail\admin\auth.py", line 182, in decorated_view
    response = view_func(request, *args, **kwargs)
  File "\.venv\lib\site-packages\django\views\generic\base.py", line 69, in view
    return self.dispatch(request, *args, **kwargs)
  File "\.venv\lib\site-packages\wagtail_localize\views\submit_translations.py", line 175, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "\.venv\lib\site-packages\django\views\generic\base.py", line 101, in dispatch
    return handler(request, *args, **kwargs)
  File "\.venv\lib\site-packages\wagtail_localize\views\submit_translations.py", line 119, in post
    return self.form_valid(form)
  File "\Python310\lib\contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "\.venv\lib\site-packages\wagtail_localize\views\submit_translations.py", line 151, in form_valid
    single_translated_object = self.object.get_translation(
  File "\.venv\lib\site-packages\wagtail\models\i18n.py", line 165, in get_translation
    return self.get_translations(inclusive=True).get(locale_id=pk(locale))
  File "\.venv\lib\site-packages\django\db\models\query.py", line 439, in get
    raise self.model.DoesNotExist(

Exception Type: DoesNotExist at /admin/localize/submit/snippet/blog/personalblogcategory/9/
Exception Value: PersonalBlogCategory matching query does not exist.
pdeero commented 1 year ago

I’m having the same error with snippets is the already a fix to handle the error [Object].DoesntExist even if the object exists?

Thanks in advance.