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

Attempting to duplicate an unsaved element. #352

Closed
lucasvallenet opened this issue May 26, 2020 · 23 comments
Closed

Attempting to duplicate an unsaved element. #352

lucasvallenet opened this issue May 26, 2020 · 23 comments
Assignees

Comments

@lucasvallenet
Copy link

Description

I have a multi-site Craft setup and a main Neo field with multiple blocks (supertable, matrix, select, ...).
When I add any block and save the entry, I encounter the following error:
"Attempting to duplicate an unsaved element."

Screen Shot 2020-05-26 at 4 46 46 PM

The error seemed the come from the supertable plugin, but I have the same issue with a matrix field.

The only work around I have for now is to Save as Draft before than Publish, but it's not the best for the end user.

Steps to reproduce

  1. Add any block (with or without supertable/matrix)
  2. Save

Other information

  • Neo version: 2.7.12
  • Craft version: 3.4.20
  • Propagation: "Save blocks to other sites in the same site group" (tried with "Save blocks to all sites the owner element is saved in" aswell)
  • No eager-loading
@richardegil
Copy link

I am having a similar issue, I couldn't tell if it was Craft or Neo causing the problem.

craftcms/cms#6142

@ttempleton
Copy link
Contributor

I've yet to reproduce the error, but I agree with the resolution from the Craft issue report that this is probably a Neo bug.

Is the involved Super Table (or Matrix) field set to the same propagation method as the Neo field?

@BSBjorn
Copy link

BSBjorn commented May 28, 2020

I am having a similar issue when trying to save an entry with a Neo field, with matrix and supertable fields inside.

The issue emerged when I added a supertable field, to an existing matrix block. The supertable first throws error for missing values in my frontend template, even when I have a test for null or empty, if i try to add the values in CP the "duplicate unsaved element" exception is thrown.

The workaround with saving draft first, then publish seems to solve the problem, but I have to forcefully set values in all fields, then save. After I can remove the values and everything works fine.

If I create a spanking new entry it will work from scratch with no errors or excetions.

@ttempleton
Copy link
Contributor

@BSBjorn, could you please let me know if your Craft installation is multi-site, and if so, what the propagation methods of the Neo, Matrix and Super Table fields are? I haven't been able to reproduce the error and I'm wondering if there is a certain combination that causes it.

@ttempleton ttempleton self-assigned this May 29, 2020
@BSBjorn
Copy link

BSBjorn commented May 29, 2020

@ttempleton My site is NOT a multisite setup. Can you set propagation on a single site?

@ttempleton
Copy link
Contributor

Thanks, @BSBjorn, and no, there are no propagation method settings on the fields on a single site. I'll keep looking into it and figure out why this is happening.

@lucasvallenet
Copy link
Author

lucasvallenet commented Jun 1, 2020

I've yet to reproduce the error, but I agree with the resolution from the Craft issue report that this is probably a Neo bug.

Is the involved Super Table (or Matrix) field set to the same propagation method as the Neo field?

My Neo field was set to "Save blocks to other sites in the same site group" and I had multiple Super Tables with a mix of propagation methods ("Save blocks to other sites in the same site group" / "Save blocks to all sites the owner element is saved in").

I've updated all my Super Table fields to have the same propagation method as the Neo field and I still have the same error.

@ttempleton
Copy link
Contributor

@lucasvallenet If possible, could you please send your composer.json/lock and database backup to [email protected]?

@ttempleton
Copy link
Contributor

Thanks for sending the files, @lucasvallenet, unfortunately I still can't reproduce the issue though... Was there a particular section or entry where it was happening?

@chadwells
Copy link

chadwells commented Jun 26, 2020

This is also happening for me, and from what I can tell, it happens like this:

  1. Already have a neo field with a structure that includes an existing Super Table field. (of note: the neo structure contains no Matrix fields, unlike previous reports on this issue)
  2. Already have an entry saved that is using that field.
  3. Add the same ST field again within the same Neo field, within some other block type.
  4. Edit the existing entry, change the value of the newly added field in your neo block, and save the entry.

(And this is on a single-site instance of Craft. )

Stack trace below.
I'm on Craft 3.4.25, Neo 2.7.20, Super Table 2.5.1

yii\base\Exception: Attempting to duplicate an unsaved element. in /shared/httpd/klipsch/vendor/craftcms/cms/src/services/Elements.php:734
Stack trace:
#0 /shared/httpd/klipsch/vendor/verbb/super-table/src/services/SuperTableService.php(917): craft\services\Elements->duplicateElement(Object(verbb\supertable\elements\SuperTableBlockElement), Array)
#1 /shared/httpd/klipsch/vendor/verbb/super-table/src/fields/SuperTableField.php(919): verbb\supertable\services\SuperTableService->duplicateBlocks(Object(verbb\supertable\fields\SuperTableField), Object(benf\neo\elements\Block), Object(benf\neo\elements\Block), true)
#2 /shared/httpd/klipsch/vendor/craftcms/cms/src/base/Element.php(2577): verbb\supertable\fields\SuperTableField->afterElementPropagate(Object(benf\neo\elements\Block), true)
#3 /shared/httpd/klipsch/vendor/craftcms/cms/src/services/Elements.php(899): craft\base\Element->afterPropagate(true)
#4 /shared/httpd/klipsch/vendor/spicyweb/craft-neo/src/services/Fields.php(335): craft\services\Elements->duplicateElement(Object(benf\neo\elements\Block), Array)
#5 /shared/httpd/klipsch/vendor/spicyweb/craft-neo/src/Field.php(652): benf\neo\services\Fields->duplicateBlocks(Object(benf\neo\Field), Object(craft\elements\Entry), Object(craft\elements\Entry), true)
#6 /shared/httpd/klipsch/vendor/craftcms/cms/src/base/Element.php(2577): benf\neo\Field->afterElementPropagate(Object(craft\elements\Entry), true)
#7 /shared/httpd/klipsch/vendor/craftcms/cms/src/elements/Entry.php(1309): craft\base\Element->afterPropagate(true)
#8 /shared/httpd/klipsch/vendor/craftcms/cms/src/services/Elements.php(899): craft\elements\Entry->afterPropagate(true)
#9 /shared/httpd/klipsch/vendor/craftcms/cms/src/services/Revisions.php(160): craft\services\Elements->duplicateElement(Object(craft\elements\Entry), Array)
#10 /shared/httpd/klipsch/vendor/craftcms/cms/src/elements/Entry.php(1313): craft\services\Revisions->createRevision(Object(craft\elements\Entry), '1', NULL)
#11 /shared/httpd/klipsch/vendor/craftcms/cms/src/services/Elements.php(2189): craft\elements\Entry->afterPropagate(false)
#12 /shared/httpd/klipsch/vendor/craftcms/cms/src/services/Elements.php(531): craft\services\Elements->_saveElementInternal(Object(craft\elements\Entry), true, false, true)
#13 /shared/httpd/klipsch/vendor/craftcms/cms/src/controllers/EntriesController.php(376): craft\services\Elements->saveElement(Object(craft\elements\Entry))
#14 [internal function]: craft\controllers\EntriesController->actionSaveEntry(false)
#15 /shared/httpd/klipsch/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#16 /shared/httpd/klipsch/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#17 /shared/httpd/klipsch/vendor/craftcms/cms/src/web/Controller.php(178): yii\base\Controller->runAction('save-entry', Array)
#18 /shared/httpd/klipsch/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('save-entry', Array)
#19 /shared/httpd/klipsch/vendor/craftcms/cms/src/web/Application.php(291): yii\base\Module->runAction('entries/save-en...', Array)
#20 /shared/httpd/klipsch/vendor/craftcms/cms/src/web/Application.php(559): craft\web\Application->runAction('entries/save-en...', Array)
#21 /shared/httpd/klipsch/vendor/craftcms/cms/src/web/Application.php(270): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#22 /shared/httpd/klipsch/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#23 /shared/httpd/klipsch/web/index.php(21): yii\base\Application->run()
#24 {main}

@ttempleton
Copy link
Contributor

@chadwells, if possible, could you please send your composer.json/lock and database backup to [email protected]? If that is possible, could you please also let us know if it only happens with certain sections, or any section that uses the affected Neo field?

@lucasvallenet
Copy link
Author

Thanks for sending the files, @lucasvallenet, unfortunately I still can't reproduce the issue though... Was there a particular section or entry where it was happening?

The issue seems to have disappeared on my side aswell, i'll get back to you if it appears again
Thank you !

@e-roc
Copy link

e-roc commented Jul 14, 2020

I am seeing the same error SuperTableService.php(917). All plugins are up to date.

yii\base\Exception: Attempting to duplicate an unsaved element. in /Users/eric/Sites/tjc/vendor/craftcms/cms/src/services/Elements.php:734
Stack trace:
#0 /Users/eric/Sites/tjc/vendor/verbb/super-table/src/services/SuperTableService.php(917): craft\services\Elements->duplicateElement(Object(verbb\supertable\elements\SuperTableBlockElement), Array)
#1 /Users/eric/Sites/tjc/vendor/verbb/super-table/src/fields/SuperTableField.php(919): verbb\supertable\services\SuperTableService->duplicateBlocks(Object(verbb\supertable\fields\SuperTableField), Object(benf\neo\elements\Block), Object(benf\neo\elements\Block), true)
#2 /Users/eric/Sites/tjc/vendor/craftcms/cms/src/base/Element.php(2577): verbb\supertable\fields\SuperTableField->afterElementPropagate(Object(benf\neo\elements\Block), true)
#3 /Users/eric/Sites/tjc/vendor/craftcms/cms/src/services/Elements.php(899): craft\base\Element->afterPropagate(true)
#4 /Users/eric/Sites/tjc/vendor/spicyweb/craft-neo/src/services/Fields.php(335): craft\services\Elements->duplicateElement(Object(benf\neo\elements\Block), Array)
#5 /Users/eric/Sites/tjc/vendor/spicyweb/craft-neo/src/Field.php(652): benf\neo\services\Fields->duplicateBlocks(Object(benf\neo\Field), Object(craft\elements\Entry), Object(craft\elements\Entry), true)
#6 /Users/eric/Sites/tjc/vendor/craftcms/cms/src/base/Element.php(2577): benf\neo\Field->afterElementPropagate(Object(craft\elements\Entry), true)
#7 /Users/eric/Sites/tjc/vendor/craftcms/cms/src/elements/Entry.php(1309): craft\base\Element->afterPropagate(true)
#8 /Users/eric/Sites/tjc/vendor/craftcms/cms/src/services/Elements.php(899): craft\elements\Entry->afterPropagate(true)
#9 /Users/eric/Sites/tjc/vendor/craftcms/cms/src/services/Revisions.php(160): craft\services\Elements->duplicateElement(Object(craft\elements\Entry), Array)
#10 /Users/eric/Sites/tjc/vendor/craftcms/cms/src/elements/Entry.php(1313): craft\services\Revisions->createRevision(Object(craft\elements\Entry), '1', NULL)
#11 /Users/eric/Sites/tjc/vendor/craftcms/cms/src/services/Elements.php(2189): craft\elements\Entry->afterPropagate(false)
#12 /Users/eric/Sites/tjc/vendor/craftcms/cms/src/services/Elements.php(531): craft\services\Elements->_saveElementInternal(Object(craft\elements\Entry), true, true, true)
#13 /Users/eric/Sites/tjc/vendor/craftcms/cms/src/controllers/EntriesController.php(376): craft\services\Elements->saveElement(Object(craft\elements\Entry))
#14 [internal function]: craft\controllers\EntriesController->actionSaveEntry(false)
#15 /Users/eric/Sites/tjc/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#16 /Users/eric/Sites/tjc/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#17 /Users/eric/Sites/tjc/vendor/craftcms/cms/src/web/Controller.php(178): yii\base\Controller->runAction('save-entry', Array)
#18 /Users/eric/Sites/tjc/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('save-entry', Array)
#19 /Users/eric/Sites/tjc/vendor/craftcms/cms/src/web/Application.php(291): yii\base\Module->runAction('entries/save-en...', Array)
#20 /Users/eric/Sites/tjc/vendor/craftcms/cms/src/web/Application.php(559): craft\web\Application->runAction('entries/save-en...', Array)
#21 /Users/eric/Sites/tjc/vendor/craftcms/cms/src/web/Application.php(270): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#22 /Users/eric/Sites/tjc/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#23 /Users/eric/Sites/tjc/web/index.php(21): yii\base\Application->run()
#24 {main}

@ttempleton
Copy link
Contributor

Could anyone who was experiencing this issue please confirm whether it still occurs with the latest versions of Craft (3.5.0), Neo (2.8.1) and Super Table (2.5.4)?

If it is still occurring, could you please confirm that here, and also send your composer.json/lock and database backup to [email protected]?

@BSBjorn
Copy link

BSBjorn commented Aug 6, 2020

I just ran into a problem when trying to update Craft from 3.4.13 to 3.5.1 ... I'm having the same issue as the above, could it be the one holding back det update?

`Performing update with Composer ... done
Applying new migrations ... error: The command "'/Users/bjornkamfjord/Sites/www.norturaproff.no/craft' 'migrate/all' '--no-backup' '--no-content'" failed.

Exit Code: 1(General error)

Working directory: /Users/bjornkamfjord/Sites/www.norturaproff.no

Output:

Yii Migration Tool (based on Yii v2.0.36)

> add column enabled boolean NOT NULL DEFAULT TRUE AFTER `primary` to table {{%sites}} ... done (time: 0.037s)
> delete from {{%templatecaches}} ... done (time: 0.001s)
> add column track string AFTER `id` to table {{%migrations}} ... done (time: 0.014s)
> update in {{%migrations}} ... done (time: 0.017s)
> update in {{%migrations}} ... done (time: 0.001s)
> update in {{%migrations}} ... done (time: 0.003s)
> update in {{%migrations}} ... done (time: 0.001s)
> update in {{%migrations}} ... done (time: 0.006s)
> update in {{%migrations}} ... done (time: 0.000s)
> update in {{%migrations}} ... done (time: 0.000s)
> update in {{%migrations}} ... done (time: 0.001s)
> update in {{%migrations}} ... done (time: 0.000s)
> update in {{%migrations}} ... done (time: 0.000s)
> update in {{%migrations}} ... done (time: 0.000s)
> update in {{%migrations}} ... done (time: 0.001s)
> update in {{%migrations}} ... done (time: 0.001s)
> update in {{%migrations}} ... done (time: 0.001s)
> update in {{%migrations}} ... done (time: 0.000s)
> update in {{%migrations}} ... done (time: 0.000s)
> update in {{%migrations}} ... done (time: 0.001s)
> update in {{%migrations}} ... done (time: 0.000s)
> update in {{%migrations}} ... done (time: 0.001s)
> update in {{%migrations}} ... done (time: 0.000s)
> update in {{%migrations}} ... done (time: 0.001s)
> update in {{%migrations}} ... done (time: 0.001s)
> update in {{%migrations}} ... done (time: 0.000s)
> update in {{%migrations}} ... done (time: 0.000s)
> alter column track in table {{%migrations}} to string NOT NULL ... done (time: 0.043s)
> create unique index migrations_track_name_unq_idx on {{%migrations}} (track,name) ...Exception: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'plugin:neo-m200313_015120_structure_update' for key 'migrations_track_name_unq_idx'

The SQL being executed was: ALTER TABLE migrations ADD UNIQUE INDEX migrations_track_name_unq_idx (track, name) (/Users/bjornkamfjord/Sites/www.norturaproff.no/vendor/yiisoft/yii2/db/Schema.php:677)
#0 /Users/bjornkamfjord/Sites/www.norturaproff.no/vendor/yiisoft/yii2/db/Command.php(1298): yii\db\Schema->convertException(Object(PDOException), 'ALTER TABLE mi...') #1 /Users/bjornkamfjord/Sites/www.norturaproff.no/vendor/yiisoft/yii2/db/Command.php(1093): yii\db\Command->internalExecute('ALTER TABLE mi...')
#2 /Users/bjornkamfjord/Sites/www.norturaproff.no/vendor/yiisoft/yii2/db/Migration.php(495): yii\db\Command->execute()
#3 /Users/bjornkamfjord/Sites/www.norturaproff.no/vendor/craftcms/cms/src/db/Migration.php(385): yii\db\Migration->createIndex('migrations_trac...', '{{%migrations}}', Array, true)
#4 /Users/bjornkamfjord/Sites/www.norturaproff.no/vendor/craftcms/cms/src/migrations/m200606_231117_migration_tracks.php(56): craft\db\Migration->createIndex('migrations_trac...', '{{%migrations}}', Array, true)
#5 /Users/bjornkamfjord/Sites/www.norturaproff.no/vendor/craftcms/cms/src/db/Migration.php(52): craft\migrations\m200606_231117_migration_tracks->safeUp()
#6 /Users/bjornkamfjord/Sites/www.norturaproff.no/vendor/craftcms/cms/src/db/MigrationManager.php(228): craft\db\Migration->up(true)
#7 /Users/bjornkamfjord/Sites/www.norturaproff.no/vendor/craftcms/cms/src/db/MigrationManager.php(148): craft\db\MigrationManager->migrateUp(Object(craft\migrations\m200606_231117_migration_tracks))
#8 /Users/bjornkamfjord/Sites/www.norturaproff.no/vendor/craftcms/cms/src/services/Updates.php(220): craft\db\MigrationManager->up()
#9 /Users/bjornkamfjord/Sites/www.norturaproff.no/vendor/craftcms/cms/src/console/controllers/MigrateController.php(328): craft\services\Updates->runMigrations(Array)
#10 [internal function]: craft\console\controllers\MigrateController->actionAll()
#11 /Users/bjornkamfjord/Sites/www.norturaproff.no/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#12 /Users/bjornkamfjord/Sites/www.norturaproff.no/vendor/yiisoft/yii2/base/Controller.php(180): yii\base\InlineAction->runWithParams(Array)
#13 /Users/bjornkamfjord/Sites/www.norturaproff.no/vendor/yiisoft/yii2/console/Controller.php(181): yii\base\Controller->runAction('all', Array)
#14 /Users/bjornkamfjord/Sites/www.norturaproff.no/vendor/yiisoft/yii2/base/Module.php(528): yii\console\Controller->runAction('all', Array)
#15 /Users/bjornkamfjord/Sites/www.norturaproff.no/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('migrate/all', Array)
#16 /Users/bjornkamfjord/Sites/www.norturaproff.no/vendor/craftcms/cms/src/console/Application.php(87): yii\console\Application->runAction('migrate/all', Array)
#17 /Users/bjornkamfjord/Sites/www.norturaproff.no/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('migrate/all', Array)
#18 /Users/bjornkamfjord/Sites/www.norturaproff.no/vendor/yiisoft/yii2/base/Application.php(386): yii\console\Application->handleRequest(Object(craft\console\Request))
#19 /Users/bjornkamfjord/Sites/www.norturaproff.no/craft(22): yii\base\Application->run()
#20 {main}

Error Output:

Exception 'craft\errors\MigrateException' with message 'An error occurred while migrating Craft CMS.'

in /Users/bjornkamfjord/Sites/www.norturaproff.no/vendor/craftcms/cms/src/services/Updates.php:235

Stack trace:
#0 /Users/bjornkamfjord/Sites/www.norturaproff.no/vendor/craftcms/cms/src/console/controllers/MigrateController.php(328): craft\services\Updates->runMigrations(Array)
#1 [internal function]: craft\console\controllers\MigrateController->actionAll()
#2 /Users/bjornkamfjord/Sites/www.norturaproff.no/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#3 /Users/bjornkamfjord/Sites/www.norturaproff.no/vendor/yiisoft/yii2/base/Controller.php(180): yii\base\InlineAction->runWithParams(Array)
#4 /Users/bjornkamfjord/Sites/www.norturaproff.no/vendor/yiisoft/yii2/console/Controller.php(181): yii\base\Controller->runAction('all', Array)
#5 /Users/bjornkamfjord/Sites/www.norturaproff.no/vendor/yiisoft/yii2/base/Module.php(528): yii\console\Controller->runAction('all', Array)
#6 /Users/bjornkamfjord/Sites/www.norturaproff.no/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('migrate/all', Array)
#7 /Users/bjornkamfjord/Sites/www.norturaproff.no/vendor/craftcms/cms/src/console/Application.php(87): yii\console\Application->runAction('migrate/all', Array)
#8 /Users/bjornkamfjord/Sites/www.norturaproff.no/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('migrate/all', Array)
#9 /Users/bjornkamfjord/Sites/www.norturaproff.no/vendor/yiisoft/yii2/base/Application.php(386): yii\console\Application->handleRequest(Object(craft\console\Request))
#10 /Users/bjornkamfjord/Sites/www.norturaproff.no/craft(22): yii\base\Application->run()
#11 {main}`

@ttempleton
Copy link
Contributor

@BSBjorn, I don't think this issue is involved with that, but it looks like a problem involving the m200313_015120_structure_update migration from Neo 2.7.0; either that it's in the migrations table twice somehow or it's tried to add it a second time for some reason. Could you please confirm whether that migration is in the migrations table more than once? If it is actually in there more than once, then it will be safe to remove the duplicates.

@GaryReckard
Copy link

GaryReckard commented Aug 13, 2020

I'm experiencing this same issue on:

  • Craft v3.4.30
  • Neo v2.7.25
  • SuperTable v2.5.4
  • Multisite: yes

@ttempleton
Copy link
Contributor

@GaryReckard, if possible, could you please send your composer.json/lock and database backup to [email protected]? If that is possible, could you please also let us know if it only happens with certain sections, or any section that uses the affected Neo field?

@GaryReckard
Copy link

Hi @ttempleton, I won't be able to share a db dump, sorry.

I just did a quick test, and I can edit and save an entry in a section that does not have the Neo-with-supertable.

@chadwells
Copy link

Hi There. Just wanted to let you know I emailed a copy of our db and composer files to assist you in fixing this issue. One thing I failed to mention in the email is we are running PHP 7.3.21

@ttempleton
Copy link
Contributor

Thanks @chadwells -- confirming that I can reproduce the error with your files. I'll keep looking into it and will update as soon as I've figured out why it's happening and how it can be fixed.

@ttempleton
Copy link
Contributor

This should now be fixed in Neo 2.8.8. I was able to reproduce this on my usual testing environment after seeing what was happening with @chadwells' database, and figured out this was happening when an otherwise-unmodified Neo block had a Super Table field added to it with either a minimum number of rows set or a static row, which will automatically create the row(s). Because the Neo block was otherwise unmodified, it was not being resaved, so the new Super Table rows were never being saved. Neo should now set such Neo blocks as modified, so the block, and therefore the new Super Table content, is saved.

@chadwells
Copy link

Can confirm fixed. Thank you!

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

No branches or pull requests

7 participants