craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.28k stars 637 forks source link

[5.x]: `Attempting to save an element in an unsupported site` when creating new nested entry for non primary site #16158

Closed dolphiq-allard closed 3 days ago

dolphiq-allard commented 5 days ago

What happened?

Description

Craft 5.5.2 throws an error (Attempting to save an element in an unsupported site) when trying to add an entry in a CKEditor field.

In a multi-lingual site I can add entries within the CKEditor field in the main language, however, in the secondary language, an error is thrown and the entry is not added to the CKEditor field. This error was introduced somewhere between version 5.1.x and 5.5.x. I've added multiple entries within the CKEditor field before upgrading to the latest version.

Error from log files:

Stack trace:
#0 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(1308): craft\services\Elements->_saveElementInternal()
#1 /var/www/html/vendor/craftcms/cms/src/services/Drafts.php(261): craft\services\Elements->saveElement()
#2 /var/www/html/vendor/craftcms/cms/src/controllers/ElementsController.php(212): craft\services\Drafts->saveElementAsDraft()
#3 [internal function]: craft\controllers\ElementsController->actionCreate()
#4 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()
#5 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams()
#6 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction()
#7 /var/www/html/vendor/craftcms/cms/src/web/Application.php(350): yii\base\Module->runAction()
#8 /var/www/html/vendor/craftcms/cms/src/web/Application.php(649): craft\web\Application->runAction()
#9 /var/www/html/vendor/craftcms/cms/src/web/Application.php(312): craft\web\Application->_processActionRequest()
#10 /var/www/html/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest()
#11 /var/www/html/web/index.php(12): yii\base\Application->run()
#12 {main} {"memory":2052936,"exception":"[object] (craft\\errors\\UnsupportedSiteException(code: 0): Attempting to save an element in an unsupported site. at /var/www/html/vendor/craftcms/cms/src/services/Elements.php:3531)"} 

This error is thrown both on production and on the development environment (DDEV)

Steps to reproduce

  1. In the secondary language version of a content page, try to add an entry to the CKEditor field

Expected behavior

The entry is added to the CKEditor field, and can be edited by double clicking it.

Actual behavior

A toast stating A server error occurred. appears and nothing else happens. The error above is logged in the logfiles.

Craft CMS version

5.5.2

PHP version

8.3.13

Operating system and version

Linux 5.10.0-32-amd64

Database type and version

MariaDB 10.6.20

Image driver and version

Imagick 3.7.0 (ImageMagick 6.9.11-60)

Installed plugins and versions

-

i-just commented 5 days ago

Hi, thanks for reporting! I raised a PR for this.

dolphiq-allard commented 5 days ago

No worries, thanks for the swift reply!

mjniland1 commented 5 days ago

This issue also affects Matrix fields on non-primary sites. When I attempt to add a new Matrix entry in a secondary site, I encounter the following errors:

Attempting to save an element in an unsupported site. Invalid owner ID: 2313

This behavior seems consistent with the issue described above and occurs in both production and development environments.

Downgrading to Craft 5.5.0.1 appears to have resolved the issue for now.

davidwebca commented 5 days ago

Aaah just found this. I had found the older issue first. Yes, I'm getting this too in 5.5.2. Reverting seems to fix the issue too.

brandonkelly commented 3 days ago

Craft 5.5.3 is out with the fix for this. Thanks again!