Closed DynamiteGoesBoom closed 2 years ago
Describe the bug
Upon attaching a category to an Entry throws an Exception error upon saving the Entry.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
No error should appear
Screenshots
Software
Additional context
Stack Trace:
Exception: 6832 in /var/www/project/cms/vendor/fostercommerce/craft-snipcart/src/models/ProductDetails.php:527 Stack trace: #0 /var/www/project/cms/vendor/fostercommerce/craft-snipcart/src/models/ProductDetails.php(541): fostercommerce\snipcart\models\ProductDetails->fostercommerce\snipcart\models\{closure}(Object(craft\elements\Entry)) #1 /var/www/project/cms/vendor/fostercommerce/craft-snipcart/src/models/ProductDetails.php(211): fostercommerce\snipcart\models\ProductDetails->skuIsUniqueElementAttribute('sku') #2 /var/www/project/cms/vendor/yiisoft/yii2/validators/InlineValidator.php(84): fostercommerce\snipcart\models\ProductDetails->validateSku('sku', NULL, Object(yii\validators\InlineValidator), 'nobody-puts-coa...') #3 /var/www/project/cms/vendor/yiisoft/yii2/validators/Validator.php(261): yii\validators\InlineValidator->validateAttribute(Object(fostercommerce\snipcart\models\ProductDetails), 'sku') #4 /var/www/project/cms/vendor/yiisoft/yii2/base/Model.php(367): yii\validators\Validator->validateAttributes(Object(fostercommerce\snipcart\models\ProductDetails), Array) #5 /var/www/project/cms/vendor/fostercommerce/craft-snipcart/src/fields/ProductDetails.php(320): yii\base\Model->validate() #6 /var/www/project/cms/vendor/craftcms/cms/src/base/Element.php(2106): fostercommerce\snipcart\fields\ProductDetails->validateProductDetails(Object(craft\elements\Entry), NULL) #7 /var/www/project/cms/vendor/yiisoft/yii2/validators/InlineValidator.php(84): craft\base\Element->validateCustomFieldAttribute('field:productDe...', Array, Object(yii\validators\InlineValidator), Object(fostercommerce\snipcart\models\ProductDetails)) #8 /var/www/project/cms/vendor/yiisoft/yii2/validators/Validator.php(261): yii\validators\InlineValidator->validateAttribute(Object(craft\elements\Entry), 'field:productDe...') #9 /var/www/project/cms/vendor/yiisoft/yii2/base/Model.php(367): yii\validators\Validator->validateAttributes(Object(craft\elements\Entry), Array) #10 /var/www/project/cms/vendor/craftcms/cms/src/services/Elements.php(2535): yii\base\Model->validate() #11 /var/www/project/cms/vendor/craftcms/cms/src/services/Elements.php(783): craft\services\Elements->_saveElementInternal(Object(craft\elements\Entry), true, false, NULL) #12 /var/www/project/cms/vendor/craftcms/cms/src/controllers/EntryRevisionsController.php(506): craft\services\Elements->saveElement(Object(craft\elements\Entry)) #13 [internal function]: craft\controllers\EntryRevisionsController->actionPublishDraft() #14 /var/www/project/cms/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array) #15 /var/www/project/cms/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array) #16 /var/www/project/cms/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('publish-draft', Array) #17 /var/www/project/cms/vendor/craftcms/cms/src/web/Application.php(287): yii\base\Module->runAction('entry-revisions...', Array) #18 /var/www/project/cms/vendor/craftcms/cms/src/web/Application.php(596): craft\web\Application->runAction('entry-revisions...', Array) #19 /var/www/project/cms/vendor/craftcms/cms/src/web/Application.php(266): craft\web\Application->_processActionRequest(Object(craft\web\Request)) #20 /var/www/project/cms/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request)) #21 /var/www/project/cms/web/index.php(21): yii\base\Application->run() #22 {main} Copy StacktraceSearch StackoverflowSearch GoogleException Exception 6832 1. in /var/www/project/cms/vendor/fostercommerce/craft-snipcart/src/models/ProductDetails.phpat line 527 518519520521522523524525526527528529530531532533534535536 ) { // Different element types with the same SKU are a conflict, as // are new and existing. $hasConflict = true; break; } $getCanonicalId = function ($element) { if (version_compare(Craft::$app->getVersion(), '3.7', '>=')) { throw new \Exception(''. $element->canonicalId); return (int) $element->canonicalId; } else { return (int) $element->sourceId; } }; if (is_a($duplicateElement, Entry::class)) { // Don’t worry about unpublished Elements. if ($duplicateElement->revisionId === null) { 2. in /var/www/project/cms/vendor/fostercommerce/craft-snipcart/src/models/ProductDetails.php at line 541– fostercommerce\snipcart\models\ProductDetails::fostercommerce\snipcart\models\{closure}(craft\elements\Entry) 535536537538539540541542543544545546547 // Don’t worry about unpublished Elements. if ($duplicateElement->revisionId === null) { continue; } // If a different Entry is using the SKU, that’s a conflict. if ($getCanonicalId($duplicateElement) !== $getCanonicalId($currentElement)) { $hasConflict = true; break; } } if (is_a($duplicateElement, MatrixBlock::class)) { 3. in /var/www/project/cms/vendor/fostercommerce/craft-snipcart/src/models/ProductDetails.php at line 211– fostercommerce\snipcart\models\ProductDetails::skuIsUniqueElementAttribute('sku') 205206207208209210211212213214215216217 * @return bool * @throws \yii\base\InvalidConfigException */ public function validateSku($attribute): bool { if (VersionHelper::isCraft32()) { $isUnique = $this->skuIsUniqueElementAttribute($attribute); } else { $isUnique = $this->skuIsUniqueRecordAttribute($attribute); } if (! $isUnique) { $this->addError($attribute, Craft::t( 4. in /var/www/project/cms/vendor/yiisoft/yii2/validators/InlineValidator.php at line 84– fostercommerce\snipcart\models\ProductDetails::validateSku('sku', null, yii\validators\InlineValidator, 'nobody-puts-coach-in-a-corner-ne...') 5. in /var/www/project/cms/vendor/yiisoft/yii2/validators/Validator.php at line 261– yii\validators\InlineValidator::validateAttribute(fostercommerce\snipcart\models\ProductDetails, 'sku') 6. in /var/www/project/cms/vendor/yiisoft/yii2/base/Model.php at line 367– yii\validators\Validator::validateAttributes(fostercommerce\snipcart\models\ProductDetails, ['sku']) 7. in /var/www/project/cms/vendor/fostercommerce/craft-snipcart/src/fields/ProductDetails.php at line 320– yii\base\Model::validate() 314315316317318319320321322323324325326 if ($element->isFieldDirty($this->handle)) { // first normalize a new value that came from the control panel $productDetails->price = Localization::normalizeNumber($productDetails->price); } $productDetails->validate(); $errors = $productDetails->getErrors(); if (count($errors) > 0) { foreach ($errors as $subfield => $subErrors) { foreach ($subErrors as $message) { 8. in /var/www/project/cms/vendor/craftcms/cms/src/base/Element.php at line 2106– fostercommerce\snipcart\fields\ProductDetails::validateProductDetails(craft\elements\Entry, null) 2100210121022103210421052106210721082109211021112112 [$field, $method, $fieldParams] = $params; if (is_string($method)) { $method = [$field, $method]; } $method($this, $fieldParams); } /** * @inheritdoc */ public function isFieldEmpty(string $handle): bool 9. in /var/www/project/cms/vendor/yiisoft/yii2/validators/InlineValidator.php at line 84– craft\base\Element::validateCustomFieldAttribute('field:productDetails', [fostercommerce\snipcart\fields\ProductDetails, 'validateProductDetails', null], yii\validators\InlineValidator, fostercommerce\snipcart\models\ProductDetails) 10. in /var/www/project/cms/vendor/yiisoft/yii2/validators/Validator.php at line 261– yii\validators\InlineValidator::validateAttribute(craft\elements\Entry, 'field:productDetails') 11. in /var/www/project/cms/vendor/yiisoft/yii2/base/Model.php at line 367– yii\validators\Validator::validateAttributes(craft\elements\Entry, ['field:productDetails']) 12. in /var/www/project/cms/vendor/craftcms/cms/src/services/Elements.php at line 2535– yii\base\Model::validate() 2529253025312532253325342535253625372538253925402541 $element->title = $element::displayName() . ' ' . $element->id; } } } // Validate if ($runValidation && !$element->validate()) { Craft::info('Element not saved due to validation error: ' . print_r($element->errors, true), __METHOD__); $element->firstSave = $originalFirstSave; $element->propagateAll = $originalPropagateAll; return false; } 13. in /var/www/project/cms/vendor/craftcms/cms/src/services/Elements.php at line 783– craft\services\Elements::_saveElementInternal(craft\elements\Entry, true, false, null) 777778779780781782783784785786787788789 $propagate = !$element->id || $propagate; // Not currently being duplicated $duplicateOf = $element->duplicateOf; $element->duplicateOf = null; $success = $this->_saveElementInternal($element, $runValidation, $propagate, $updateSearchIndex); $element->duplicateOf = $duplicateOf; return $success; } /** * Merges recent canonical element changes into a given derivative, such as a draft. 14. in /var/www/project/cms/vendor/craftcms/cms/src/controllers/EntryRevisionsController.php at line 506– craft\services\Elements::saveElement(craft\elements\Entry) 500501502503504505506507508509510511512 ) { $draft->setIsFresh(); $draft->propagateAll = true; } try { if (!Craft::$app->getElements()->saveElement($draft)) { throw new InvalidElementException($draft); } // Apply the draft (finally!) $isDerivative = $draft->getIsDerivative(); if ($isDerivative) { 15. craft\controllers\EntryRevisionsController::actionPublishDraft() 16. in /var/www/project/cms/vendor/yiisoft/yii2/base/InlineAction.php at line 57– call_user_func_array([craft\controllers\EntryRevisionsController, 'actionPublishDraft'], []) 17. in /var/www/project/cms/vendor/yiisoft/yii2/base/Controller.php at line 178– yii\base\InlineAction::runWithParams([]) 18. in /var/www/project/cms/vendor/yiisoft/yii2/base/Module.php at line 552– yii\base\Controller::runAction('publish-draft', []) 19. in /var/www/project/cms/vendor/craftcms/cms/src/web/Application.php at line 287– yii\base\Module::runAction('entry-revisions/publish-draft', []) 281282283284285286287288289290291292293 * @param string $route * @param array $params * @return Response|null The result of the action, normalized into a Response object */ public function runAction($route, $params = []) { $result = parent::runAction($route, $params); if ($result !== null) { if ($result instanceof Response) { return $result; } 20. in /var/www/project/cms/vendor/craftcms/cms/src/web/Application.php at line 596– craft\web\Application::runAction('entry-revisions/publish-draft', []) 590591592593594595596597598599600601602 if ($request->getIsActionRequest()) { $route = implode('/', $request->getActionSegments()); try { Craft::debug("Route requested: '$route'", __METHOD__); $this->requestedRoute = $route; return $this->runAction($route, $_GET); } catch (\Throwable $e) { $this->_unregisterDebugModule(); if ($e instanceof InvalidRouteException) { throw new NotFoundHttpException(Craft::t('yii', 'Page not found.'), $e->getCode(), $e); } throw $e; 21. in /var/www/project/cms/vendor/craftcms/cms/src/web/Application.php at line 266– craft\web\Application::_processActionRequest(craft\web\Request) 260261262263264265266267268269270271272 throw new ForbiddenHttpException(); } } } // If this is an action request, call the controller if (($response = $this->_processActionRequest($request)) !== null) { return $response; } // If we're still here, finally let Yii do it's thing. try { return parent::handleRequest($request); 22. in /var/www/project/cms/vendor/yiisoft/yii2/base/Application.php at line 384– craft\web\Application::handleRequest(craft\web\Request) 23. in /var/www/project/cms/web/index.php at line 21– yii\base\Application::run() 15161718192021 Dotenv\Dotenv::create(CRAFT_BASE_PATH)->load(); } // Load and run Craft define('CRAFT_ENVIRONMENT', getenv('ENVIRONMENT') ?: 'production'); $app = require CRAFT_VENDOR_PATH.'/craftcms/cms/bootstrap/web.php'; $app->run(); $_POST = [ 'CRAFT_CSRF_TOKEN' => 'vtMD5rdGPXGbIkcTzgolUvkS3VPggB0C69NtIEt7H1YoGdyWqu_EsZXCdEYCE_gWj8hj9RlR6LiH9vqkuBMs-0iuQPAUG9TlYkJU8tNhH40qmnBSaTqZ0CEr_Mti6N596JhxcsBymgMRZd0Fx2z7auVRciZXyUwwTauMT4oAsoXhdL0ypx6J1KACuQotSWQaMunREPXWWs2gdEQGa1dhhAFufU-yO5HhzsQN5wOux-bYV8R0cUjratvnL2N2rB6coPpaAPKwAsQIvFatuw29392LMLCaDE0a9BUqQL5QECW4ebM4rOx7VJyQAn86ITIlYCCU-_qG9IDp8Ud1NiHPd7n-Us17M9GK4cHPnY8hT8p9n3SWJSzm0FF0ZMe3US-6H61DMAoO_OYZGMr4Bt7rHtGpE0f2QagzdAaFNpFBsRqOPkVLBLkWBTrq5yHhTN7jtwP-Xfhv0_nTSoBCQBkNKgOV4GzR5CPpkUdgY0QTWPNTAx8G9wKgsK2UToJu16mErWeoGAUYqD7t1mIgDMNr5OTJPlKIyVioa-t4_Y1mj4w=', 'action' => 'entry-revisions/publish-draft', 'redirect' => '516ed101179a94e8e13bee9d4234ca49bfdc56c35ca23d7bd01759558491fc6aentries/shop', 'sectionId' => '9', 'sourceId' => '6832', 'title' => 'Coach\'s Corner', 'typeId' => '11', 'slug' => 'coachs-corner', 'parentId' => '', 'author' => [ '1', ], 'postDate' => [ 'date' => '6/1/2021', 'timezone' => 'America/Denver', 'time' => '7:24 PM', ], 'expiryDate' => [ 'date' => '', 'timezone' => 'America/Denver', 'time' => '', ], 'enabled' => '1', 'notes' => '', 'draftId' => '57', 'provisional' => '1', 'draftName' => 'Draft 1', ]; $_COOKIE = [ '1031b8c41dfff97a311a7ac99863bdc5_username' => '1dd2a59522bac5058567d3285d99c415ed5baed40d388926dde1c6544ca52d8ca:2:{i:0;s:41:"1031b8c41dfff97a311a7ac99863bdc5_username";i:1;s:23:"hi@hybridinteractive.io";}', 'critical-css' => '', 'CRAFT_CSRF_TOKEN' => '423c614487ff7241f4018ab8985721e91e4c260b82aa11c68cdfa713433e9a2ca:2:{i:0;s:16:"CRAFT_CSRF_TOKEN";i:1;s:208:"cX3V-Jpko7mSpZ5wAknkLlfVwCo_qZ-sH9HmPi01|333427a6618bb92f75972c1514f17253605d007573bc4e68363d65c91b56320ecX3V-Jpko7mSpZ5wAknkLlfVwCo_qZ-sH9HmPi01|1|$2y$13$e/D9wRmbIE91QcPCemynbu0lltPCT61MCzouxD3dRzyZlcW.P6k2S";}', 'CraftSessionId' => 'a4079764313d60d960cfc9dbf5ac55b4', '1031b8c41dfff97a311a7ac99863bdc5_identity' => 'cbe16eb9a4e5d3b0de2a743f4ff5a8f4cf7dc5d7eb75b33c7a533fe864804812a:2:{i:0;s:41:"1031b8c41dfff97a311a7ac99863bdc5_identity";i:1;s:159:"[1,"[\\"yUb-y1wLu2yE96dTBg_w6dfeu7xQATDdI8Zbt7_ImEXU1ZBP9uKbGveNbNMuoGc3iJUQFm1FmlGQoxvRyZte6VThX4zZ8FZI8I6i\\",null,\\"8ffec38781748c07c6d2e71b451e2e28\\"]",3600]";}', ]; $_SESSION = [ 'bd62416aa8538ede709019a5e113eea5__flash' => [], '__duration' => 3600, 'bd62416aa8538ede709019a5e113eea5__auth_access' => [ 'seomaticPreviewAuthorizationKey25', 'previewElement:25', 'saveAssetInVolume:8', 'saveAssetInVolume:5', 'saveAssetInVolume:4', 'saveAssetInVolume:7', 'saveAssetInVolume:6', 'saveAssetInVolume:1', 'previewDraft:45', 'seomaticPreviewAuthorizationKey8350', 'previewDraft:46', 'seomaticPreviewAuthorizationKey8360', 'editStructure:5', 'seomaticPreviewAuthorizationKey6832', 'previewElement:6832', 'previewDraft:57', 'seomaticPreviewAuthorizationKey8615', ], '1031b8c41dfff97a311a7ac99863bdc5__token' => 'yUb-y1wLu2yE96dTBg_w6dfeu7xQATDdI8Zbt7_ImEXU1ZBP9uKbGveNbNMuoGc3iJUQFm1FmlGQoxvRyZte6VThX4zZ8FZI8I6i', '1031b8c41dfff97a311a7ac99863bdc5__id' => 1, '__authKey' => '["yUb-y1wLu2yE96dTBg_w6dfeu7xQATDdI8Zbt7_ImEXU1ZBP9uKbGveNbNMuoGc3iJUQFm1FmlGQoxvRyZte6VThX4zZ8FZI8I6i",null,"8ffec38781748c07c6d2e71b451e2e28"]', '1031b8c41dfff97a311a7ac99863bdc5__expire' => 1641860122, ]; Yii Framework 2022-01-10, 16:15:22 nginx/1.19.10 Yii Framework/2.0.44
Thanks for the help!
UPDATE:
I thought this was related to adding a Category, but even if you just open an entry with the Snipcart field snd save it that error appears regardless.
@DynamiteGoesBoom this is resolved in 1.5.7 - There was some logic that I had accidentally left in for debugging, it is removed now.
Most excellent @johnnynotsolucky and I'll have a look!
Thanks again!
Describe the bug
Upon attaching a category to an Entry throws an Exception error upon saving the Entry.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
No error should appear
Screenshots
Software
Additional context
Stack Trace:
Thanks for the help!
UPDATE:
I thought this was related to adding a Category, but even if you just open an entry with the Snipcart field snd save it that error appears regardless.