craftcms / cms

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

[3.x]: Data loss in Matrix field when saved too quickly #12456

Closed johnj24 closed 1 year ago

johnj24 commented 1 year ago

What happened?

Description

I thought that maybe this update would fix the issue, but we're still getting data loss in a matrix field if the entry is saved too quickly. On an already published entry, if I add a block to the matrix and hit cmd+s before the field revision gets autosaved (before the blue border appears to the left), I get unexpected data loss in the matrix field.

https://user-images.githubusercontent.com/1458917/207673772-0e9dcd87-e700-4145-ac52-a2545635a97b.mov

Steps to reproduce

  1. Create matrix field with one block (I don't think it matters which fields are added the block, but we have one user field and one dropdown field)
  2. Add it to a section
  3. Create an entry in the section and add a matrix block or two, hit save.
  4. Return to the newly created entry
  5. Add a new block to the matrix and hit save immediately
  6. The newly refreshed page will have missing matrix rows.

Expected behavior

The matrix field should have all data still intact.

Actual behavior

The matrix field is completely stripped of data.

Craft CMS version

3.7.61

PHP version

7.4.3

Operating system and version

Linux 5.4.0-126

Database type and version

MySQL 8.0.31

Image driver and version

Imagick 3.4.4 (ImageMagick 6.9.10-23)

Installed plugins and versions

Amazon S3 1.3.0 Freeform 3.13.2 Imager X v3.5.5 Linkit 1.1.12.1 Navigation 1.4.24 Notifier 0.9.5 Postmark 2.1.0 Redactor 2.10.4 SEO 3.4.26 Sprig 1.13.0 Sprout Fields 3.8.5 Super Table 2.7.1 Wordsmith 3.3.0.1

brianjhanson commented 1 year ago

Thanks for reporting! Unfortunately, I'm having trouble replicating this one. Are there any errors in the browser console that might provide a clue? Or is there anything in the storage/logs files that might be related?

denisyilmaz commented 1 year ago

we have similar issues in craft 4, loosing matrix/neo blocks on save and sometimes resulting in "corrupt" indexes in the database. FOr some just data is lost. FOr others we get full "internal server errors":

SQLSTATE[HY000]: General error: 1712 Index neoblocks is corrupted The SQL being executed was: SELECT `elements`.`id`, `elements`.`canonicalId`, `elements`.`fieldLayoutId`, `elements`.`uid`, `elements`.`enabled`, `elements`.`archived`, `elements`.`dateLastMerged`, `elements`.`dateCreated`, `elements`.`dateUpdated`, `elements_sites`.`id` AS `siteSettingsId`, `elements_sites`.`slug`, `elements_sites`.`siteId`, `elements_sites`.`uri`, `elements_sites`.`enabled` AS `enabledForSite`, `elements`.`dateDeleted`, `neoblocks`.`fieldId`, `neoblocks`.`primaryOwnerId`, `neoblocks`.`typeId`, `neoblocks_owners`.`ownerId`, `neoblocks_owners`.`sortOrder`, `content`.`id` AS `contentId`, `content`.`field_anchorId_gydnoqng`, `content`.`field_answer_sjhyvwjk`, `content`.`field_credits_wviketss`, `content`.`field_curatedItems_hjeipzgh`, `content`.`field_description_lptcuzep`, `content`.`field_destination_uxpyybny`, `content`.`field_emailAddress_pxpusdib`, `content`.`field_oEmbed_kenpvqdg`, `content`.`field_entityName_ykjhtnne`, `content`.`field_eventStatus_uyebonci`, `content`.`field_eventStatusReason_phjahoqq`, `content`.`field_heading_jdwckule`, `content`.`field_headingAnimated_uzabpqvg`, `content`.`field_displayHeading_hpktitrk`, `content`.`field_hideHeading_wgdyirtj`, `content`.`field_highlight_ituciuhs`, `content`.`field_infoText_dbbmubxe`, `content`.`field_isOnline_bfpnaaha`, `content`.`field_label_kugusxbz`, `content`.`field_listItemsLegacy`, `content`.`field_mediaPosition_odtlwpla`, `content`.`field_mediaSize_yxofpygp`, `content`.`field_metaDescription_jqoivlrf`, `content`.`field_metaTitle_qkndhsja`, `content`.`field_onlineEventUrl_toakfhoc`, `content`.`field_pageLayout_pkbcjydt`, `content`.`field_phoneNumber_tgkfnwlb`, `content`.`field_physicalAddress_vjbiqtcl`, `content`.`field_positionX_eqmpijeo`, `content`.`field_positionY_rodtqwap`, `content`.`field_question_lfpgwfty`, `content`.`field_removeSpacing_yetzkyrx`, `content`.`field_seoSettings_rtjzgena`, `content`.`field_showAnchor_nfnpozbc`, `content`.`field_showAsOverlay_ombiftxf`, `content`.`field_showIndexes_ntymfgvo`, `content`.`field_showMap_busmyoax`, `content`.`field_showMapLink_nbreuzmc`, `content`.`field_showNewsletterPopup_kjrytbsk`, `content`.`field_sourceName_xcgdfhbw`, `content`.`field_sourceLink_aaufdrlm`, `content`.`field_statusText_fisexchc`, `content`.`field_subheading_pmkmbfru`, `content`.`field_text_sgdzsfts`, `content`.`field_websiteUrl_ooremhfc`, `content`.`field_calendarEventId_tjuswfdc`, `content`.`field_coconutOutputs_fywrtwmh`, `content`.`field_fullHeading_dpksjbgx`, `content`.`field_metaInfo_zoeuwehm`, `content`.`field_wordpressAltText_pxyelsea`, `content`.`field_wordpressFocalPointX_livpunks`, `content`.`field_wordpressFocalPointY_ytwgwuax`, `content`.`field_wordpressId_sshehnhi`, `content`.`field_wordpressSlug_oziwunht`, `content`.`field_wordpressUrl_tvusbgmt`, `structureelements`.`root`, `structureelements`.`lft`, `structureelements`.`rgt`, `structureelements`.`level`, `structureelements`.`structureId` FROM (SELECT `elements`.`id` AS `elementsId`, `elements_sites`.`id` AS `elementsSitesId`, `content`.`id` AS `contentId`, `structureelements`.`structureId` FROM `elements` `elements` INNER JOIN `neoblocks` `neoblocks` ON `neoblocks`.`id` = `elements`.`id` INNER JOIN `neoblocks_owners` `neoblocks_owners` ON (`neoblocks_owners`.`blockId` = `elements`.`id`) AND (`neoblocks_owners`.`ownerId` = `neoblocks`.`primaryOwnerId`) INNER JOIN `elements_sites` `elements_sites` ON `elements_sites`.`elementId` = `elements`.`id` INNER JOIN `content` `content` ON `content`.`elementId` = `elements`.`id` LEFT JOIN `structureelements` `structureelements` ON (`structureelements`.`elementId` = `elements`.`id`) AND (EXISTS (SELECT * FROM `structures` use index(primary) WHERE (`id` = `structureelements`.`structureId`) AND (`dateDeleted` IS NULL))) WHERE (`neoblocks`.`fieldId`=10) AND (`neoblocks`.`primaryOwnerId`=16) AND (`elements`.`archived`=FALSE) AND (`elements`.`draftId` IS NULL) AND (`elements`.`revisionId` IS NULL) ORDER BY `lft`) `subquery` INNER JOIN `elements` `elements` ON `elements`.`id` = `subquery`.`elementsId` INNER JOIN `elements_sites` `elements_sites` ON `elements_sites`.`id` = `subquery`.`elementsSitesId` INNER JOIN `neoblocks` `neoblocks` ON `neoblocks`.`id` = `subquery`.`elementsId` INNER JOIN `neoblocks_owners` `neoblocks_owners` ON (`neoblocks_owners`.`blockId` = `elements`.`id`) AND (`neoblocks_owners`.`ownerId` = `neoblocks`.`primaryOwnerId`) INNER JOIN `content` `content` ON `content`.`id` = `subquery`.`contentId` LEFT JOIN `structureelements` `structureelements` ON (`structureelements`.`elementId` = `subquery`.`elementsId`) AND (`structureelements`.`structureId` = `subquery`.`structureId`) ORDER BY `lft` {"trace":["#0 /home/deignis-prod/webapps/deignis-web-production/releases/1673432744065/vendor/yiisoft/yii2/db/

image

The error appeared first when upgrading to Craft CMS 4.3.6.1

brianjhanson commented 1 year ago

@denisyilmaz any chance this site is on, or started on MySQL 8.0.29? There was a particularly "fun" bug in MySQL 8.0.29 that would result in corrupted indexes and manifests in Craft when adding or removing Matrix, Neo, or Super Table blocks. It's especially likely if the database or server was created back in August or September. Around that time 8.0.29 was the default version for many distros.

If that might be the case, the only fix is to provision a fresh install with 8.0.30+, dump out your database and restore it on the new box.

@johnj24 are you seeing similar logs by chance?

brandonkelly commented 1 year ago

Closing this for now due to inactivity. @denisyilmaz feel free to reply if you can provide more info, though.

denisyilmaz commented 1 year ago

@brandonkelly sorry for not getting back to you here. my colleague was in contact with you via email. we setup a new server with fresh database installed and got rid of the issue. It seems the server installation was corrupt as it was not the mentioned MySQL version.

Thanks again!

ubiqworld commented 8 months ago

We've simply copied the "corrupt" database with phpMyAdmin into a completely empty and new database. This fully solved the error.