Hello,
I am learning the product attribute/variation system and came across an issue today. I created two "Test" attributes and enabled them on my Product Variation. I then created a test product and added variations based on those attributes.
My testing complete, I deleted the two "Test" attributes. Now, I am unable to access the edit screen of my product variation that had those attributes enabled. I have tried clearing cache, but that did not fix the issue.
The on-screen error is: "The website encountered an unexpected error. Please try again later."
The log error message is:
TypeError: Argument 1 passed to Drupal\commerce_product\ProductAttributeFieldManager::canDeleteField() must implement interface Drupal\commerce_product\Entity\ProductAttributeInterface, null given, called in /home/mysite/public_html/modules/commerce/modules/product/src/Form/ProductVariationTypeForm.php on line 127 in Drupal\commerce_product\ProductAttributeFieldManager->canDeleteField() (line 216 of /home/mysite/public_html/modules/commerce/modules/product/src/ProductAttributeFieldManager.php) #0 /home/mysite/public_html/modules/commerce/modules/product/src/Form/ProductVariationTypeForm.php(127): Drupal\commerce_product\ProductAttributeFieldManager->canDeleteField(NULL, 'shippable_produ...') #1 /home/mysite/public_html/core/lib/Drupal/Core/Entity/EntityForm.php(117): Drupal\commerce_product\Form\ProductVariationTypeForm->form(Array, Object(Drupal\Core\Form\FormState)) #2 [internal function]: Drupal\Core\Entity\EntityForm->buildForm(Array, Object(Drupal\Core\Form\FormState)) #3 /home/mysite/public_html/core/lib/Drupal/Core/Form/FormBuilder.php(519): call_user_func_array(Array, Array) #4 /home/mysite/public_html/core/lib/Drupal/Core/Form/FormBuilder.php(276): Drupal\Core\Form\FormBuilder->retrieveForm('commerce_produc...', Object(Drupal\Core\Form\FormState)) #5 /home/mysite/public_html/core/lib/Drupal/Core/Controller/FormController.php(93): Drupal\Core\Form\FormBuilder->buildForm('commerce_produc...', Object(Drupal\Core\Form\FormState)) #6 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch)) #7 /home/mysite/public_html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array) #8 /home/mysite/public_html/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #9 /home/mysite/public_html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #10 /home/mysite/public_html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) #11 /home/mysite/public_html/vendor/symfony/http-kernel/HttpKernel.php(151): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #12 /home/mysite/public_html/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) #13 /home/mysite/public_html/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #14 /home/mysite/public_html/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #15 /home/mysite/public_html/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #16 /home/mysite/public_html/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true) #17 /home/mysite/public_html/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #18 /home/mysite/public_html/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #19 /home/mysite/public_html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #20 /home/mysite/public_html/core/lib/Drupal/Core/DrupalKernel.php(693): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #21 /home/mysite/public_html/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #22 {main}.
I'm sure i shouldn't have deleted the attribute the way that I did, but this seems like something that could be screwed up really easy, causing a website to partially crash like this. I do have a database backup, but I wanted to see if anyone could tell me how to fix the issue instead.