We need to make sure ProductVariationContext properly implements ContextProviderInterface and doesn't return a populated context value in getAvailableContexts
Original summary
Dummy orphans paragraphs are generated when adding a product
We have discovered that dummy orphans paragraphs are generated from this class whenever visiting the page for adding a new product ex "product/add/my_product": "modules/contrib/commerce/modules/product/src/ContextProvider/ProductVariationContext.php"
.
$value = $this->productVariationStorage->createWithSampleValues($product_type->getVariationTypeId());
Could you please let me know what purpose this class has?
Backtrace
"69: call_user_func_array()" => array:1 [▶]
"68: Drupal\Core\Extension\ModuleHandler->invokeAll()" => array:2 [▶]
"67: Drupal\Core\Entity\EntityStorageBase->invokeHook()" => array:2 [▶]
"66: Drupal\Core\Entity\ContentEntityStorageBase->invokeHook()" => array:2 [▶]
"65: Drupal\Core\Entity\EntityStorageBase->doPostSave()" => array:2 [▶]
"64: Drupal\Core\Entity\ContentEntityStorageBase->doPostSave()" => array:2 [▶]
"63: Drupal\Core\Entity\EntityStorageBase->save()" => array:2 [▶]
"62: Drupal\Core\Entity\Sql\SqlContentEntityStorage->save()" => array:2 [▶]
"61: Drupal\Core\Entity\EntityBase->save()" => array:1 [▶]
"60: Drupal\entity_reference_revisions\Plugin\Field\FieldType\EntityReferenceRevisionsItem::generateSampleValue()" => array:2 [▶]
"59: Drupal\Core\Field\FieldItemList->generateSampleItems()" => array:1 [▶]
"58: Drupal\Core\Entity\ContentEntityStorageBase->createWithSampleValues()" => array:2 [▶]
"57: Drupal\commerce_product\ContextProvider\ProductVariationContext->getRuntimeContexts()" => array:2 [▼
"file" => "modules/contrib/commerce/modules/product/src/ContextProvider/ProductVariationContext.php:68"
"args" => array:1 [▶]
]
"56: Drupal\commerce_product\ContextProvider\ProductVariationContext->getAvailableContexts()" => array:1 [▼
"file" => "modules/contrib/commerce/modules/product/src/ContextProvider/ProductVariationContext.php:108"
]
"55: Drupal\Core\Plugin\Context\LazyContextRepository->getAvailableContexts()" => array:1 [▼
"file" => "core/lib/Drupal/Core/Plugin/Context/LazyContextRepository.php:97"
]
"54: Drupal\Core\ParamConverter\EntityConverter->convert()" => array:2 [▼
"file" => "core/lib/Drupal/Core/ParamConverter/EntityConverter.php:137"
"args" => array:4 [▶]
]
"53: Drupal\Core\ParamConverter\ParamConverterManager->convert()" => array:2 [▶]
"52: Drupal\Core\Routing\Enhancer\ParamConversionEnhancer->enhance()" => array:2 [▶]
"51: Drupal\Core\Routing\Router->applyRouteEnhancers()" => array:2 [▶]
"50: Drupal\Core\Routing\Router->matchRequest()" => array:2 [▶]
"49: Drupal\Core\Routing\AccessAwareRouter->matchRequest()" => array:2 [▶]
"48: Drupal\easy_breadcrumb\EasyBreadcrumbBuilder->getRequestForPath()" => array:2 [▶]
"47: Drupal\easy_breadcrumb\EasyBreadcrumbBuilder->setRouteContextFromRouteMatch()" => array:2 [▶]
"46: Drupal\easy_breadcrumb\EasyBreadcrumbBuilder->build()" => array:2 [▶]
"45: Drupal\Core\Breadcrumb\BreadcrumbManager->build()" => array:2 [▶]
"44: Drupal\system\Plugin\Block\SystemBreadcrumbBlock->build()" => array:1 [▶]
"43: Drupal\block\BlockViewBuilder::preRender()" => array:2 [▶]
"42: call_user_func_array()" => array:1 [▶]
"41: Drupal\Core\Render\Renderer->doTrustedCallback()" => array:2 [▶]
"40: Drupal\Core\Render\Renderer->doCallback()" => array:2 [▶]
"39: Drupal\Core\Render\Renderer->doRender()" => array:2 [▶]
"38: Drupal\Core\Render\Renderer->doRender()" => array:2 [▶]
"37: Drupal\Core\Render\Renderer->render()" => array:2 [▶]
"36: Drupal\Core\Template\TwigExtension->escapeFilter()" => array:2 [▶]
"35: __TwigTemplate_fc9a7a0fd32477138130107a3402b8fc3d20ad5942e433f078f6542c4f355847->doDisplay()" => array:2 [▶]
"34: Twig\Template->displayWithErrorHandling()" => array:2 [▶]
"33: Twig\Template->display()" => array:2 [▶]
"32: Twig\Template->render()" => array:2 [▶]
"31: twig_render_template()" => array:2 [▶]
"30: Drupal\Core\Theme\ThemeManager->render()" => array:2 [▶]
"29: Drupal\Core\Render\Renderer->doRender()" => array:2 [▶]
"28: Drupal\Core\Render\Renderer->render()" => array:2 [▶]
"27: Drupal\Core\Template\TwigExtension->escapeFilter()" => array:2 [▶]
"26: __TwigTemplate_9344828e5a1144cf2a4a5b4597d4abfc38a6b9311b6adbae0902880d49e082fc->doDisplay()" => array:2 [▶]
"25: Twig\Template->displayWithErrorHandling()" => array:2 [▶]
"24: Twig\Template->display()" => array:2 [▶]
"23: Twig\Template->render()" => array:2 [▶]
"22: twig_render_template()" => array:2 [▶]
"21: Drupal\Core\Theme\ThemeManager->render()" => array:2 [▶]
"20: Drupal\Core\Render\Renderer->doRender()" => array:2 [▶]
"19: Drupal\Core\Render\Renderer->render()" => array:2 [▶]
"18: Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}()" => array:1 [▶]
"17: Drupal\Core\Render\Renderer->executeInRenderContext()" => array:2 [▶]
"16: Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse()" => array:2 [▶]
"15: Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()" => array:2 [▶]
"14: call_user_func()" => array:1 [▶]
"13: Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch()" => array:2 [▶]
"12: Symfony\Component\HttpKernel\HttpKernel->handleRaw()" => array:2 [▶]
"11: Symfony\Component\HttpKernel\HttpKernel->handle()" => array:2 [▶]
"10: Drupal\Core\StackMiddleware\Session->handle()" => array:2 [▶]
" 9: Drupal\Core\StackMiddleware\KernelPreHandle->handle()" => array:2 [▶]
" 8: Drupal\page_cache\StackMiddleware\PageCache->pass()" => array:2 [▶]
" 7: Drupal\page_cache\StackMiddleware\PageCache->handle()" => array:2 [▶]
" 6: Drupal\ban\BanMiddleware->handle()" => array:2 [▶]
" 5: Drupal\shield\ShieldMiddleware->handle()" => array:2 [▶]
" 4: Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()" => array:2 [▶]
" 3: Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()" => array:2 [▶]
" 2: Stack\StackedHttpKernel->handle()" => array:2 [▶]
" 1: Drupal\Core\DrupalKernel->handle()" => array:2 [▶]
" 0: main()" => array:2 [▶]
]
If a bug, provide steps to reproduce it from a clean install.
@todo
Issue fork commerce-3220015
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
jsacksick CreditAttribution: jsacksick at Centarro commentedDuplicate of #3190799: ProductVariationContext is causing extra generate sample images to be generated.
Comment #3
jsacksick CreditAttribution: jsacksick at Centarro commentedActually, going to reopen this as I'm not entirely sure this is a duplicate.
It looks like this code is kicking off even when Layout builder is not used...
Comment #4
mglaman@jsacksick thanks for re-opening, this is a problem of its own.
We generated a sample variation for when using the Default Layout manager. This shouldn't be happening when adding a new product. Definitely a big bug.
Thanks for the backtrace, super helpful!
Comment #5
mglamanI wasn't able to reproduce on the latest 8.x-2.x. In the backtrace, I noticed Easy Breadcrumb builder. I wonder if #3200588: Core BreadcrumbBuilder might lead to fatal PHP error in ProductVariationContext fixed this.
Have you tried on the latest 2.x or only on 8.x-2.24?
Comment #6
mglamanThe problem is that ContextProviderInterface is improperly implemented.
::getAvailableContexts
always returns a populated context value, when it should be a stub.Comment #7
mglamanLinking to #3099968: Layout builder incorrectly resolves global contexts values when viewing layouts which prevents from not having a hacky fix.
Comment #9
mglamanActually, I think this fix would be the proper fix for #3200588: Core BreadcrumbBuilder might lead to fatal PHP error in ProductVariationContext as well.
Comment #10
mglamanComment #11
mglamanComment #12
mkalkbrennerWe'll test it after the weekend. Thanks for your work!
Comment #13
jsacksick CreditAttribution: jsacksick at Centarro commentedI'm confused, I don't get how reverting the commit that fixes #3200588: Core BreadcrumbBuilder might lead to fatal PHP error in ProductVariationContext could fix this bug, considering the fix in in dev only and the bug was originally reported against 2.24.
Additionally, the fix from from #3200588: Core BreadcrumbBuilder might lead to fatal PHP error in ProductVariationContext only ensures that even if the route parameter type isn't specified (which could be the case when the route is defined by a view for example), the logic doesn't crash.
I think support product IDS is "ok", considering how views defines its routes, otherwise that would require people using views to write a route subscriber that's altering the route.
Comment #14
lexsoft CreditAttribution: lexsoft commentedIn our case the context module https://www.drupal.org/project/context, where we had a context on product variations and whenever we were going to product variation display it was creating dummy paragraphs.
And with https://www.drupal.org/project/easy_breadcrumb we had a few field paragraphs in the variation and whenever visiting the add/product page dummy orphans paragraphs are generated.
We have applied patch 4 from here https://www.drupal.org/project/commerce/issues/3190799 and it seems the issue has stopped.
From our investigation, it seemed that anything connected to commerce that uses Drupal context
new RequestContext();
will triggermodules/contrib/commerce/modules/product/src/ContextProvider/ProductVariationContext.php
.Comment #15
lexsoft CreditAttribution: lexsoft commentedBacktrace for context contrib module:
Comment #16
jsacksick CreditAttribution: jsacksick at Centarro commented@mglaman: As discussed on Slack, If we can confirm that:
This is no longer needed, we can safely revert.
Comment #17
mglaman@lexsoft yeah, it's due to the ContextProviderInterface not being implemented properly due to a bug in LayoutBuilder. The getAvailableContexts should not return the values from runtime. But basically empty-value context definitions. That is what this issue aims to resolve.
Random content will be fixed in #3190799: ProductVariationContext is causing extra generate sample images to be generated
Comment #18
mglamanI just mered #3190799: ProductVariationContext is causing extra generate sample images to be generated, which means this probably has conflicts.
https://git.drupalcode.org/issue/commerce-3220015/-/tree/3220015-dummy-o... is still viable to test, just patching to 8.x-2.x HEAD will probably error until I rebase.
Comment #19
cspitzlayI've tried to reproduce the problem from #3200588: Core BreadcrumbBuilder might lead to fatal PHP error in ProductVariationContext with the 3220015-dummy-orphans-paragraphs branch and our project code and migrated data. No crash, seems to work.
Comment #20
mglamanRebased.
@lexsoft your backtrace shows issues with ProductRouteContext not ProductVariationContext in the backtrace. Is this the case?
Comment #22
mglamanCommitted the MR. I'm sure there are more gremlins – like in ProductRouteContext, even. But it is a good step forward.
Thanks, everyone!
Comment #23
lexsoft CreditAttribution: lexsoft commented@mglaman Yes, when used with https://www.drupal.org/project/context contrib module it was the ProductRouteContext that was triggered.
We used the contrib context module for layouts display conditions. After visiting any product type page, like manage display form or manage display. The context was triggered.