Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
If there is a paragraph where there is no field data (perhaps related to https://www.drupal.org/project/paragraphs/issues/2741937), the total count does not match the actual count since the count query is using a different mechanism.
Proposed resolution
Count in the same way as the fetchall.
Patch to come shortly.
Comment | File | Size | Author |
---|---|---|---|
#23 | interdiff-19-23.txt | 478 bytes | azinck |
#23 | paragraphs-update-endless-loop-3041868-23.patch | 1.27 KB | azinck |
#10 | paragraphs-update-endless-loop-3041868-10-D8.patch | 1.06 KB | scott_euser |
#19 | interdiff_10-19.txt | 1.18 KB | alesr |
#19 | paragraphs-update-endless-loop-3041868-19.patch | 1.06 KB | alesr |
Comments
Comment #2
scott_euser CreditAttribution: scott_euser as a volunteer and at Soapbox Communications Ltd commentedGiven that the loading of all items to be updated is using a select query:
updated count to match:
Comment #3
jasonlttl CreditAttribution: jasonlttl at Ohio State University commentedNote, even with the patch I'm still seeing an infinite loop in cases where there are zero paragraph content entities.
Comment #4
JimCraner CreditAttribution: JimCraner commentedConfirmed, we have zero paragraphs and the updatedb command hangs in a Divide by 0 loop on the _8018 update:
[notice] Update started: paragraphs_update_8018
[warning] Division by zero paragraphs.install:349
[notice] 0 Paragraphs processed.
Comment #5
bkosborneThis seems pretty major to me. I wouldn't say critical, because if you don't have any paragraph entities, then it's clear you're not using the module.
Comment #6
David Radcliffe CreditAttribution: David Radcliffe at Triplo commentedI had the same problem, but since I had no paragraph entities, I was able to resolve the problem by uninstalling and reinstalling the module.
Comment #7
alberto56 CreditAttribution: alberto56 at Dcycle commentedWith the patch, I no longer get the division by zero, but I still get the infinite loop:
In my continuous integration server, I have this module enabled with an empty database using a previous schema, and my C.I. server attempts to run the updates, to make sure no error occurs. So in my case, I do want to have the module enabled for the CI server even though there's no content.
Comment #8
websiteworkspace CreditAttribution: websiteworkspace commentedI've just experienced the same error when updating the paragraphs module just now:
1 - the first update attempt (using composer), went into an infinite loop that issued the following output endlessly before being canceled.
2 - After aborting with Ctrl-C, I run composer, and then drush update again and the following output was issued:
Comment #9
scott_euser CreditAttribution: scott_euser as a volunteer and at Soapbox Communications Ltd commentedSo two remaining issues to add to the patch:
Will update the patch as soon as I am behind a computer.
Comment #10
scott_euser CreditAttribution: scott_euser as a volunteer and at Soapbox Communications Ltd commentedUpdated patch now to cover cases where no Paragraphs exist and where user has run updb, got caught in endless loop, arrived here, and applied patch (ie, allowing them to re-run without fatal error).
Comment #11
corE CreditAttribution: corE commented3-20-19 [not sure which section to post this in],
I have been getting a failed paragraphs update from 1.6 to 1.7 and my log has multiple entries of "Warning: Division by zero in paragraphs_update_8018()":
The following updates returned messages:
paragraphs module
Update #8018
Failed: Drupal\Core\Database\SchemaObjectExistsException: Cannot add field paragraphs_item_revision_field_data.parent_id: field already exists. in Drupal\Core\Database\Driver\mysql\Schema->addField() (line 414 of ...core/lib/Drupal/Core/Database/Driver/mysql/Schema.php).
The database update says I may need to "update your database manually". I manually rolled it back to 1.6 - Still showing errors on status page though.
Comment #12
scott_euser CreditAttribution: scott_euser as a volunteer and at Soapbox Communications Ltd commentedApplying the patch in https://www.drupal.org/project/paragraphs/issues/3041868#comment-13032310 should solve that for you @corE
Comment #13
blueblot CreditAttribution: blueblot commentedsame problem as in #8
tried the latest patch but no luck.
Comment #14
priyanka1989 CreditAttribution: priyanka1989 as a volunteer commentedSame problem as #11
paragraphs module
Update #8018
Failed: Drupal\Core\Database\SchemaObjectExistsException: Cannot add field paragraphs_item_revision_field_data.parent_id: field already exists. in Drupal\Core\Database\Driver\mysql\Schema->addField() (line 414 of /Users/DevAdmin/Sites/devdesktop/cummins-test/docroot/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php)
Comment #15
cedrichillion CreditAttribution: cedrichillion as a volunteer commentedSame issue and still not being able to update after applying https://www.drupal.org/project/paragraphs/issues/3041868#comment-13032310
Subsequently, trying to run drush entity-updates gives me this error message:
Comment #16
alesr CreditAttribution: alesr at NDP commentedYou get into an endless loop because of this line
$sandbox['#finished'] = ($sandbox['current'] / $sandbox['total']);
If $sandbox['total'] is 0, it will never finish.
So probably you don't have any paragraphs in your database if you get this error.
Patch #10 didn't work for me either, so here is patch #16.
Comment #17
bander2 CreditAttribution: bander2 as a volunteer commented16 fixes it for me.
Comment #18
scott_euser CreditAttribution: scott_euser as a volunteer and at Soapbox Communications Ltd commentedFixes to other issues we're removed in #16. Please build from existing patches and provide interdiffs.
Comment #19
alesr CreditAttribution: alesr at NDP commentedComment #20
alesr CreditAttribution: alesr at NDP commentedComment #21
ahebrank CreditAttribution: ahebrank commentedI'll put in a vote for the fix in #16 addressing the primary cause of this problem and as such should be hotfixed. If deploying between staged environments, that check should be sufficient.
I *think* the rest of #10 and possibly stuff like #15 are secondary effects from 8018 failing the first time, which may be worked around by restoring the db from a backup (or live/test environment), applying #16, and updating again.
#19 is probably OK, but the fact that there are two levels of bugs at work makes this tougher to review.
Comment #22
Jon Pollard CreditAttribution: Jon Pollard commentedFor me, patch #19 didn't work - left my site dead. Patch #16 however has done the trick. The site has no paragraph content but does have the module installed.
Comment #23
azinck CreditAttribution: azinck at Forum One commented#10 has the right idea of needing to fix the query that comes up with the total count because it's possible to have a mis-match between the number of paragraph entities and the number of records in the paragraphs_item_field_data table, but the count query provided in #10 is still wrong (caused only one batch to run, rather than updating all paragraph records).
I've fixed that here, and have incorporated the other fixes from #19 since they look right to me.
Comment #24
jurgenhaasPatch from #23 applies nicely and works as expected.
Comment #25
scott_euser CreditAttribution: scott_euser as a volunteer and at Soapbox Communications Ltd commentedThanks for updating it!
Well part of 10 handles paragraphs not cleaned up which result in a count mismatch as per the original issue summary. The rest are cleanup on failed updates yes.
Comment #26
hunterbuchanan CreditAttribution: hunterbuchanan commentedAnother vote of confidence for #23 patch, seems to work great. Thank you all!
Comment #27
alasserrHi,
I've encounterd this problem as I had no paragraphs.
I just replaced the line 349 of paragraphs.install with this one:
$sandbox['#finished'] = ($sandbox['total'] == 0) ?? ($sandbox['current'] / $sandbox['total']);
See, if no paragraphs are to process ($sandbox['total']) then no process is run.
Have a good day
Adrien
Comment #28
ro-no-lo CreditAttribution: ro-no-lo commentedBtw. if someone, like me, was stuck with a situation that update 8019 is the latest according to the keyvalue schema entry for paragraphs. The situation for me was, that the revision table still had no entries in parent_id, parent_type and praent_field_name, which in turn resulted in problems down the road where paragraph executes ->getParentType() (or something like that).
Anyway, I looked at the .install updates and wrote this sql, which copies the fields from one table to the revision table, which shall be done in 8018.
You just have to execute this once. If you wanna ultrashure, you may add IS NULL checks for the fields. Anyway the update 8019 should then be executed without problems. Therefore you have to set the 8018 schema value in the keyvalue store for paragraphs to make it work for the update.php call.
Comment #29
blueblot CreditAttribution: blueblot commented#23 patch works fine. Thx!
Comment #30
ccshannon CreditAttribution: ccshannon commentedI actually thought I had created some Paragraphs (I have several Paragraph bundles/types I am testing with), but I got the infinite loop problem, but I guess I hadn't created any, or had deleted the ones I had created for testing. Patch #23 fixed the issue and I got this in the output from drush:
So, just to note, again, that it is not unusual to be developing a project that has Paragraphs configured but no actual Paragraphs in the DB.
Great that people jumped on this and released patches, so thanks to @azinck.
Comment #31
TomSaw CreditAttribution: TomSaw commented#23 worked. Dankeschön!
Comment #32
fonant CreditAttribution: fonant commentedPatch #23 worked for me. Thanks!
Comment #33
Florent Jousseaume CreditAttribution: Florent Jousseaume commentedHello,
The #23 works fine for me.
Thank you !
Comment #35
miro_dietikerThank you all for the quick improvements proposals and reviews.
Committed #23, will create a new release shortly.
Comment #36
astringer CreditAttribution: astringer as a volunteer commentedI was not able to updb, I also had 3 entity/field definition mismatches.
I patched with #23.
It allowed me to drush updb, but I am still getting mismatched entity/field definitions for one of the three fields -- Parent ID field.
I ran drush entup and got the following error:
I just took over managing this site, and it appears there are no paragraphs in the database, but I don't know this module very well, and would just like it to update — so I can figure out why there is a paragraph type set up but apparently no paragraphs....later.
Anyone know how to cleanly and easily clear this?
Comment #37
David Radcliffe CreditAttribution: David Radcliffe at Triplo commentedIf there is no paragraph content then the quickest solution is to uninstall and reinstall Paragraphs.
Comment #38
ccshannon CreditAttribution: ccshannon commentedThanks, @David Radcliffe. I have several Paragraph Types custom configured (though, yes, they are exported to .yml), and was worried that might be an issue, so I admit, I didn't try.
Comment #39
Farnoosh CreditAttribution: Farnoosh commentedThank you #37. On Core 8.6.13 and lightning 3.207 with no paragraph content, reinstalling Paragraphs module fixed the issue.
Comment #40
azovsky CreditAttribution: azovsky commentedThe last dev version (or #23 patch) of the module not working, unfortunately. Still an endless loop on `Performing paragraphs_update_8018`.
Comment #41
BerdirAre you sure it's endless? How much data do you have? it can take a while if you have a lot of paragraphs.
Comment #42
azovsky CreditAttribution: azovsky commentedActually, I'm not sure... I have a lot of content! E.g. the paragraphs_item_field_data table has ~ 32K rows. In this case how many "updates" can I see? 32000/50=640 ? But I see ~ 2K "Performing paragraphs_update_8018 [ok]" lines in my CLI in ~ 30 min.! I don't think is it okay.
Comment #43
BerdirNo, that doesn't seem OK, but you will need to debug it somehow to figure out why it doesn't finish, there might be something off with your data, some kind of inconsistency. I'd suggest you open a new issue and try to provide more details.