craftcms / cms

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

'Element [id] could not be duplicated because it "doens't" validate' while re-saving entries #4958

Closed benjaminkohl closed 5 years ago

benjaminkohl commented 5 years ago

Description

We updated a client site to Craft 3.3.4.1 this morning and now they are unable to change and save many of their entries. When they click save, the request errors out. We checked the log and apparently the element is being duplicated as part of the revisions logic and it is not passing validation. An exception is thrown but it isn't handled gracefully so we don't know where to start looking into what isn't passing validation. The entries in question were saving just fine prior to the update.

Here is the entire stack trace:

2019-09-18 09:13:24 [-][1][e36fa526045be4f23c691219d7b3cd2d][error][craft\errors\InvalidElementException] craft\errors\InvalidElementException: Element 53448 could not be duplicated because it doens't validate. in /home/serveruser/domains/domain.org/prod/vendor/craftcms/cms/src/services/Elements.php:717
Stack trace:
#0 /home/serveruser/domains/domain.org/prod/vendor/craftcms/cms/src/services/Revisions.php(166): craft\services\Elements->duplicateElement(Object(craft\elements\Entry), Array)
#1 /home/serveruser/domains/domain.org/prod/vendor/craftcms/cms/src/elements/Entry.php(1155): craft\services\Revisions->createRevision(Object(craft\elements\Entry), 3, 'Revision from J...')
#2 /home/serveruser/domains/domain.org/prod/vendor/craftcms/cms/src/services/Elements.php(1836): craft\elements\Entry->beforeSave(false)
#3 /home/serveruser/domains/domain.org/prod/vendor/craftcms/cms/src/services/Elements.php(488): craft\services\Elements->_saveElementInternal(Object(craft\elements\Entry), true, false)
#4 /home/serveruser/domains/domain.org/prod/vendor/craftcms/cms/src/controllers/EntriesController.php(378): craft\services\Elements->saveElement(Object(craft\elements\Entry))
#5 [internal function]: craft\controllers\EntriesController->actionSaveEntry(false)
#6 /home/serveruser/domains/domain.org/prod/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#7 /home/serveruser/domains/domain.org/prod/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#8 /home/serveruser/domains/domain.org/prod/vendor/craftcms/cms/src/web/Controller.php(187): yii\base\Controller->runAction('save-entry', Array)
#9 /home/serveruser/domains/domain.org/prod/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('save-entry', Array)
#10 /home/serveruser/domains/domain.org/prod/vendor/craftcms/cms/src/web/Application.php(299): yii\base\Module->runAction('entries/save-en...', Array)
#11 /home/serveruser/domains/domain.org/prod/vendor/craftcms/cms/src/web/Application.php(566): craft\web\Application->runAction('entries/save-en...', Array)
#12 /home/serveruser/domains/domain.org/prod/vendor/craftcms/cms/src/web/Application.php(278): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#13 /home/serveruser/domains/domain.org/prod/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#14 /home/serveruser/domains/domain.org/prod/public/index.php(28): yii\base\Application->run()
#15 {main}

Steps to reproduce

  1. Update Craft from 3.2.10 to 3.3.4.1
  2. Open entry form in control panel and either click the save button or do cmd+s.

Additional info

Amazon S3 1.2.5 Button Box 2.0.4 Cache Flag 1.0.3 CP Field Inspect 1.0.6 Feed Me 4.1.2 Freeform 3.4.1 Hvrcraft 3.0.0-beta.4 Imager v2.2.0 Inventory 2.0.3 Linkit 1.1.11 Link Vault 3.0.5.3 Many to Many Field Type 1.0.2.2 Maps 3.6.4.3 Position Fieldtype 1.0.14 Redactor 2.4.0 Relabel 1.3.3 Relations 1.2.1 Retour 3.1.24 SEOmatic 3.2.24 Sidebar Entry Types 1.0.3 Spoon 3.3.7 Super Table 2.3.0 Typogrify 1.1.18

benjaminkohl commented 5 years ago

We tracked down the cause for this in one entry and I think we'll find similar cases throughout the site. We had a text field with a length limit on it and the entry had been previously saved with a value that was too long for that field. It is possible that the long text value came through Feed Me.

If we tried to shorten that value via the CP form and save the entry, the same error described above occurs—maybe because it is trying to save a copy of the entry in its original state? I manually fixed the value in that text field using a DB query then we were able to re-save the entry from the control panel without getting an error.

brandonkelly commented 5 years ago

If we tried to shorten that value via the CP form and save the entry, the same error described above occurs—maybe because it is trying to save a copy of the entry in its original state?

That would make sense if versioning had recently been turned on for the section, so Craft needed to save an initial revision for the entry before saving a new one. However I just tried reproducing locally, with these steps:

  1. Create a text field with no char limit set
  2. Create a section with versioning disabled, and the field selected
  3. Create an entry with a large value
  4. Add a char limit to the field and enable versioning on the section
  5. Open entry, verify that it already shows a validation error on the field
  6. Verify that the entry has no revisions yet
  7. Resave the entry with a shorter value that does validate

When doing that, a new revision is created with the field’s original value, even though it didn’t validate by the time the revision was created. No errors or anything.

Do you happen to have a database backup that I could reproduce your error with? If so can you please send that and your composer.json & composer.lock files over to support@craftcms.com?

nicbou commented 4 years ago

This is still an issue. I used Feed Me to import posts from another blog. This specific entry had a field value that was longer than the allowed maximum. I can't save that entry, even if the new value is shorter.

brandonkelly commented 4 years ago

@nicbou Please ensure you are running the latest version of Craft and Feed Me. If the issue still occurs, then please post a new issue over at https://github.com/craftcms/feed-me.