statikbe / craft-deepl

Apache License 2.0
3 stars 0 forks source link

Error when loading entry from CP #9

Open williamhibberd opened 8 months ago

williamhibberd commented 8 months ago

Using verson 1.1 of the plugin, I am getting an error when visiting an entry in the CMS.

Impossible to access an attribute ("groupId") on a null variable.

The line in the error message that references groudId {% set otherSites = entry.section.siteSettings|filter(v => v.siteId != selectedSite.id and craft.app.sites.getSiteById(v.siteId).groupId == selectedSite.groupId) %}

The plugin seemed to be working fine before I renamed my default site from DEFAULT to en

Full error message:

Twig\Error\RuntimeError: Impossible to access an attribute ("groupId") on a null variable. in /var/www/html/vendor/statikbe/craft-deepl/src/templates/_cp/_entries.twig:15
Stack trace:
#0 /var/www/html/vendor/craftcms/cms/src/helpers/Template.php(129): twig_get_attribute(Object(craft\web\twig\Environment), Object(Twig\Source), NULL, 'groupId', Array, 'any', false, false)
#1 /var/www/html/storage/runtime/compiled_templates/9c/9c776601f90ac6f09bd4e0ebf410f7dc.php(70): craft\helpers\Template::attribute(Object(craft\web\twig\Environment), Object(Twig\Source), NULL, 'groupId', Array)
#2 [internal function]: __TwigTemplate_1b53a69c1cb36c4bba25acd449183619->{closure}(Object(craft\models\Section_SiteSettings), 3)
#3 /var/www/html/vendor/twig/twig/src/Extension/CoreExtension.php(1655): array_filter(Array, Object(Closure), 1)
#4 /var/www/html/vendor/craftcms/cms/src/web/twig/Extension.php(1132): twig_array_filter(Object(craft\web\twig\Environment), Array, Object(Closure))
#5 /var/www/html/storage/runtime/compiled_templates/9c/9c776601f90ac6f09bd4e0ebf410f7dc.php(70): craft\web\twig\Extension->filterFilter(Object(craft\web\twig\Environment), Array, Object(Closure))
#6 /var/www/html/vendor/twig/twig/src/Template.php(394): __TwigTemplate_1b53a69c1cb36c4bba25acd449183619->doDisplay(Array, Array)
#7 /var/www/html/vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#8 /var/www/html/vendor/twig/twig/src/Template.php(379): Twig\Template->display(Array)
#9 /var/www/html/vendor/twig/twig/src/TemplateWrapper.php(40): Twig\Template->render(Array, Array)
#10 /var/www/html/vendor/twig/twig/src/Environment.php(277): Twig\TemplateWrapper->render(Array)
#11 /var/www/html/vendor/craftcms/cms/src/web/View.php(482): Twig\Environment->render('deepl/_cp/_entr...', Array)
#12 /var/www/html/vendor/statikbe/craft-deepl/src/Deepl.php(66): craft\web\View->renderTemplate('deepl/_cp/_entr...', Array)
#13 [internal function]: statikbe\deepl\Deepl->statikbe\deepl\{closure}(Object(craft\events\DefineHtmlEvent))
#14 /var/www/html/vendor/yiisoft/yii2/base/Event.php(312): call_user_func(Object(Closure), Object(craft\events\DefineHtmlEvent))
#15 /var/www/html/vendor/yiisoft/yii2/base/Component.php(642): yii\base\Event::trigger('craft\\elements\\...', 'defineSidebarHt...', Object(craft\events\DefineHtmlEvent))
#16 /var/www/html/vendor/craftcms/cms/src/base/Element.php(4874): yii\base\Component->trigger('defineSidebarHt...', Object(craft\events\DefineHtmlEvent))
#17 /var/www/html/vendor/craftcms/cms/src/controllers/ElementsController.php(1037): craft\base\Element->getSidebarHtml(false)
#18 /var/www/html/vendor/craftcms/cms/src/controllers/ElementsController.php(422): craft\controllers\ElementsController->_editorSidebar(Object(craft\elements\Entry), false, true)
#19 /var/www/html/vendor/craftcms/cms/src/controllers/ElementsController.php(867): craft\controllers\ElementsController->craft\controllers\{closure}(Object(craft\models\FieldLayoutForm))
#20 /var/www/html/vendor/craftcms/cms/src/controllers/ElementsController.php(449): craft\controllers\ElementsController->_prepareEditor(Object(craft\elements\Entry), false, true, Object(craft\web\Response), 'main-form', Object(Closure), Object(Closure), Object(Closure))
#21 [internal function]: craft\controllers\ElementsController->craft\controllers\{closure}(Object(craft\web\Response), 'main-form')
#22 /var/www/html/vendor/craftcms/cms/src/web/CpScreenResponseFormatter.php(121): call_user_func(Object(Closure), Object(craft\web\Response), 'main-form')
#23 /var/www/html/vendor/craftcms/cms/src/web/CpScreenResponseFormatter.php(49): craft\web\CpScreenResponseFormatter->_formatTemplate(Object(craft\web\Response), Object(craft\web\CpScreenResponseBehavior))
#24 /var/www/html/vendor/yiisoft/yii2/web/Response.php(1100): craft\web\CpScreenResponseFormatter->format(Object(craft\web\Response))
#25 /var/www/html/vendor/craftcms/cms/src/web/Response.php(337): yii\web\Response->prepare()
#26 /var/www/html/vendor/yiisoft/yii2/web/Response.php(340): craft\web\Response->prepare()
#27 /var/www/html/vendor/yiisoft/yii2/base/Application.php(390): yii\web\Response->send()
#28 /var/www/html/web/index.php(12): yii\base\Application->run()
#29 {main}
williamhibberd commented 7 months ago

I suspect this issue may be related to caching. Today, I conducted some tests on a new database, which unfortunately led to encountering additional problems.

While configuring my sites, which support seven different languages, I encountered an issue with the depreciation of the Portuguese language code, 'pt'. Despite setting the language to 'pt-PT,' I continued to encounter the deprecation error.

In an attempt to resolve this, I considered deleting the Portuguese site and adding it again. However, this approach resulted in encountering the aforementioned 'Impossible to access an attribute ("groupId") on a null variable' error once again.

janhenckens commented 7 months ago

Hey @williamhibberd, could you give us a bit more context regarding the setup of the sites and sitegroups in your install?

Regarding the renaming & removing of sites, were there any propagation jobs still running in the queue at the time you get the error? (and are you still seeing the error once all these jobs have finished running?)

williamhibberd commented 7 months ago

Sure I have recorded this screen cast to show you what is going on: https://www.loom.com/share/b8f7bcdaecaa48cc995414322e8e4bc5

janhenckens commented 7 months ago

Thanks for that, I can reproduce the issue on our end.

The problem lies in entry.section.siteSettings, which still includes settings for the site that was deleted. These settings get clean up once Craft's internal garbage collection runs but before that they contain data for a site that doesn't exist anymore. I'll see how we can work around that and if we should report this as an issue with Craft itself.

williamhibberd commented 7 months ago

Ok brilliant so if I run php craft gc/run it should resolve my issues

williamhibberd commented 7 months ago

Garbage collection worked for the first issue, but I am still having problems with translating to pt-PT. I don't want to hassle, but just letting you know.

janhenckens commented 7 months ago

Ok brilliant so if I run php craft gc/run it should resolve my issues

Yes, that should do the trick.

janhenckens commented 7 months ago

Garbage collection worked for the first issue, but I am still having problems with translating to pt-PT. I don't want to hassle, but just letting you know.

We're currently passing the full locale to DeepL as it is set in Craft, in your case that is pt-PT. Which DeepL stopped supporting, but they do still support pt. We'll look at a fix where we fall back to to the shorter locale.

I'll report back when we have a fix!

williamhibberd commented 7 months ago

The error indicates that the situation might be reversed. It appears that 'pt' is not supported, but the locale 'pt-PT' is. Despite configuring the locale to 'pt-PT,' the error persists.

throw new DeepLException('targetLang="pt" is deprecated, please use "pt-PT" or "pt-BR" instead.');