Problem/Motivation
If a "Create" form has a field that kicks off an Ajax call (e.g. an image upload field), the $leaf_lifetime can easily exceed 60 seconds, causing a fatal error:
AssertionError: assert($leaf_lifetime <= 60) in assert() (line 97 of /app/web/modules/contrib/subgroup/src/Entity/GroupSubgroupHandler.php)
Steps to reproduce
- Create subgroup with an image field.
- Go to form to create a subgroup entity.
- Fill in required fields.
- Choose an image so it gets added to form via Ajax (showing the Alt field).
- Wait more than 60 seconds.
- Hit "Save" button.
This will cause the error here because apparently $child->getCreatedTime() gets set when the Ajax call is made:
$leaf_lifetime = $this->time->getCurrentTime() - $child->getCreatedTime();
assert($leaf_lifetime <= 60);
Proposed resolution
Somehow make sure that $child->getCreatedTime() does not get set with Ajax calls made before the entity is actually saved.
Remaining tasks
Create patch.
User interface changes
None.
API changes
None.
Data model changes
None.
Comments
Comment #2
jrbI've attached a patch that makes the leaf lifetime calculation use
$child->getChangedTime()rather than$child->getCreatedTime(). This fixes the problem that we're seeing with the Ajax callback because the "changed time" looks to be reset when the entity is actually saved.Would this still prevent whatever it is that the
assert()is trying to prevent?Comment #3
kristiaanvandeneyndeThe reason we check vs created time is because you really should not be adding existing groups into a tree unless you absolutely know what you're doing. That's why it's an assert rather than an exception, as you can ignore asserts on production but they really ought to show up during development and testing.
Having said that, if the entity's create time is indeed set as soon as the form is loaded and you're using the right form (as explained in the IS), I can see how people will hit the 60 second limit. So what we could do, is make sure the entity's create time is set during form submit, rather than form instantiation.
Comment #4
kristiaanvandeneyndeComment #5
scotwith1tIn our situation,
was not relevant. Rather than adding existing groups into a tree, we were simply creating a new subgroup and by the time I fill out the form (there are a handful of content fields for each group on this build, all needed for the front-end display of the group), we hit this assert almost every single time. Not sure if it was that or just the fact that we are using Paragraphs heavily on the Group entity and thus the ajax call was the culprit even if we quickly filled out the form, but the patch works as expected/advertised. Thx!
Comment #6
jrbThis
assert()was removed in #3163044: Leaf lifetime exceeds 60s in large migrations, so this is no longer an issue in any branch (1.x, 2.x, and 3.x).