nystudio107 / craft-similar

Similar for Craft lets you find elements, Entries, Categories, Commerce Products, etc, that are similar, based on... other related elements.
https://nystudio107.com/
MIT License
26 stars 5 forks source link

Craft 5 upgrade – Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 16 #52

Closed klick closed 3 months ago

klick commented 3 months ago

Describe the bug

After upgrading to Craft 5 I get the following error:

Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 16

when calling

{% set similarProductsByTags = craft.similar.find({ element: product, context: product.schlagwoerter }) %}

in my product detail view template.

Versions

Similar: dev-develop-v5

Craft: Craft Pro 5.2.0

Commerce: Pro 5.0.10.1

Database: type: mariadb, version: "10.4"

PHP: 8.2

Screenshots

image
khalwat commented 3 months ago

Can you include the complete error as text (rather than a screenshot) so I can search through it?

klick commented 3 months ago

Hi Andrew.

I should have done that but I have since made a new clean install. I had some other errors here too like not being able to change currency on my craft commerce store and so on so I decided to quickly start over.

I am in the middle of re-creating the data in Craft and also the front end with my old templates so if that error pops up again I will update this issue. Until that we can treat this as resolved.

Best Marcus

klick commented 3 months ago

So, same error as above on a fresh install. Tags or no tags attached makes no difference.

Full error text:

Database Exception – yii\db\Exception SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 16 The SQL being executed was: SELECT elements.id, elements_sites.siteId, COUNT(*) AS count FROM (SELECT elements.id AS elementsId, elements_sites.id AS siteSettingsId FROM elements elements INNER JOIN commerce_products commerce_products ON commerce_products.id = elements.id INNER JOIN elements_sites elements_sites ON elements_sites.elementId = elements.id LEFT JOIN relations relations ON elements.id = relations.sourceId WHERE (NOT (elements.id=238)) AND (elements_sites.siteId=1) AND (relations.targetId IN (199, 200)) AND (((elements.enabled=TRUE) AND (elements_sites.enabled=TRUE)) AND (commerce_products.postDate <= '2024-06-17 11:02:16') AND ((commerce_products.expiryDate IS NULL) OR (commerce_products.expiryDate > '2024-06-17 11:02:16'))) AND (elements.archived=FALSE) AND (elements.dateDeleted IS NULL) AND (elements.draftId IS NULL) AND (elements.revisionId IS NULL) GROUP BY elements.id, content.id, elements_sites.id ORDER BY commerce_products.postDate DESC) subquery INNER JOIN elements elements ON elements.id = subquery.elementsId INNER JOIN elements_sites elements_sites ON elements_sites.id = subquery.siteSettingsId INNER JOIN commerce_products commerce_products ON commerce_products.id = subquery.elementsId LEFT JOIN relations relations ON elements.id = relations.sourceId WHERE relations.targetId IN (199, 200) GROUP BY relations.sourceId, elements.id, elements_sites.siteId ORDER BY count, Error Info: Array ( [0] => 42000 [1] => 1064 [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 16 ) ↵ Caused by: PDOException SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 16 in /var/www/html/vendor/yiisoft/yii2/db/Command.php at line 1320

  1. in /var/www/html/vendor/yiisoft/yii2/db/Schema.phpat line 676 667668669670671672673674675676677678679680681682683684685 $exceptionClass = '\yii\db\Exception'; foreach ($this->exceptionMap as $error => $class) { if (strpos($e->getMessage(), $error) !== false) { $exceptionClass = $class; } } $message = $e->getMessage() . "\nThe SQL being executed was: $rawSql"; $errorInfo = $e instanceof \PDOException ? $e->errorInfo : null; return new $exceptionClass($message, $errorInfo, $e->getCode(), $e); }

    /**

    • Returns a value indicating whether a SQL statement is for read purpose.
    • @param string $sql the SQL statement
    • @return bool whether a SQL statement is for read purpose. */ public function isReadQuery($sql) {
  2. in /var/www/html/vendor/yiisoft/yii2/db/Command.php at line 1325– [yii\db\Schema::convertException](https://www.yiiframework.com/doc-2.0/yii-db-schema.html#convertException()-detail)(PDOException, 'SELECT elements.id, `element...')
  3. in /var/www/html/vendor/yiisoft/yii2/db/Command.php at line 1186– [yii\db\Command::internalExecute](https://www.yiiframework.com/doc-2.0/yii-db-command.html#internalExecute()-detail)('SELECT elements.id, `element...')
  4. in /var/www/html/vendor/yiisoft/yii2/db/Command.php at line 417– [yii\db\Command::queryInternal](https://www.yiiframework.com/doc-2.0/yii-db-command.html#queryInternal()-detail)('fetchAll', null)
  5. in /var/www/html/vendor/yiisoft/yii2/db/Query.php at line 249– [yii\db\Command::queryAll](https://www.yiiframework.com/doc-2.0/yii-db-command.html#queryAll()-detail)()
  6. in /var/www/html/vendor/craftcms/cms/src/db/Query.php at line 256– [yii\db\Query::all](https://www.yiiframework.com/doc-2.0/yii-db-query.html#all()-detail)(null) 250251252253254255256257258259260261262 * @inheritdoc

    • @return array<TKey,TValue> */ public function all($db = null): array { try { return parent::all($db); } catch (QueryAbortedException) { return []; } }

    /**

  7. in /var/www/html/vendor/craftcms/cms/src/elements/db/ElementQuery.php at line 1778– craft\db\Query::all(null) 1772177317741775177617771778177917801781178217831784 if ($this->with) { Craft::$app->getElements()->eagerLoadElements($this->elementType, $cachedResult, $this->with); } return $cachedResult; }

    return $this->eagerLoad()?->all() ?? parent::all($db);

    }

    /**

    • @param YiiConnection|null $db
    • @return ElementCollection<TKey,TElement> */
  8. in /var/www/html/vendor/nystudio107/craft-similar/src/services/Similar.php at line 114– craft\elements\db\ElementQuery::all() 108109110111112113114115116117118119120 $query->andWhere(['elements_sites.siteId' => $element->siteId]); }

    $query->andWhere(['in', 'relations.targetId', $tagIds]);
    $query->leftJoin(['relations' => Table::RELATIONS], '[[elements.id]] = [[relations.sourceId]]');
    
    $results = $query->all();
    
    // Fetch the elements based on the returned `id` and `siteId`
    $queryConditions = [];
    $similarCounts = [];
    
    // Build the query conditions for a new element query.
  9. in /var/www/html/vendor/nystudio107/craft-similar/src/variables/SimilarVariable.php at line 35– nystudio107\similar\services\Similar::find(['element' => craft\commerce\elements\Product, 'context' => craft\elements\db\TagQuery]) 293031323334353637 *
    • @return array|ElementInterface
    • @throws Exception */ public function find(array $data): array|ElementInterface { return Similar::$plugin->similar->find($data); } }
  10. in /var/www/html/vendor/twig/twig/src/Extension/CoreExtension.php at line 1635– nystudio107\similar\variables\SimilarVariable::find(['element' => craft\commerce\elements\Product, 'context' => craft\elements\db\TagQuery])
  11. in /var/www/html/vendor/craftcms/cms/src/helpers/Template.php at line 141– twig_get_attribute(craft\web\twig\Environment, Twig\Source, nystudio107\similar\variables\SimilarVariable, 'find', ...) 135136137138139140141142143144145146147 if (is_object($value) && get_class($value) === Markup::class) { $arguments[$key] = (string)$value; } }

    try {
        return twig_get_attribute(
            $env,
            $source,
            $object,
            $item,
            $arguments,
            $type,
  12. in /var/www/html/templates/artikel.twig at line 4– craft\helpers\Template::attribute(craft\web\twig\Environment, Twig\Source, nystudio107\similar\variables\SimilarVariable, 'find', ...) 12345678910{% extends '_layout' %} {% set cart = craft.commerce.carts.cart %} {% set limitCriteria = craft.entries().limit(4) %} {% set similarProductsByTags = craft.similar.find({ element: product, context: product.tags }) %} {# {% set similarProductsByTags = craft.similar.find({ element: product, context: product.schlagwoerter }) %} #} {% set variants = product.getVariants() %}

{% block content %}

13. in /var/www/html/vendor/twig/twig/src/Template.php at line 394– [__TwigTemplate_136af783244a05f4de8513bdb7249cb5::doDisplay](http://twig.sensiolabs.org/api/2.x/Twig/Template.html#method_doDisplay)(['product' => craft\commerce\elements\Product, 'variables' => ['product' => craft\commerce\elements\Product], 'craft' => craft\web\twig\variables\CraftVariable, 'currentSite' => craft\models\Site, ...], ['content' => [__TwigTemplate_136af783244a05f4de8513bdb7249cb5, 'block_content']]) 14. in /var/www/html/vendor/twig/twig/src/Template.php at line 367– [Twig\Template::displayWithErrorHandling](http://twig.sensiolabs.org/api/2.x/Twig/Template.html#method_displayWithErrorHandling)(['product' => craft\commerce\elements\Product, 'variables' => ['product' => craft\commerce\elements\Product], 'craft' => craft\web\twig\variables\CraftVariable, 'currentSite' => craft\models\Site, ...], ['content' => [__TwigTemplate_136af783244a05f4de8513bdb7249cb5, 'block_content']]) 15. in /var/www/html/vendor/twig/twig/src/Template.php at line 379– [Twig\Template::display](http://twig.sensiolabs.org/api/2.x/Twig/Template.html#method_display)(['product' => craft\commerce\elements\Product, 'variables' => ['product' => craft\commerce\elements\Product]]) 16. in /var/www/html/vendor/twig/twig/src/TemplateWrapper.php at line 38– [Twig\Template::render](http://twig.sensiolabs.org/api/2.x/Twig/Template.html#method_render)(['product' => craft\commerce\elements\Product, 'variables' => ['product' => craft\commerce\elements\Product]]) 17. in /var/www/html/vendor/twig/twig/src/Environment.php at line 280– [Twig\TemplateWrapper::render](http://twig.sensiolabs.org/api/2.x/Twig/TemplateWrapper.html#method_render)(['product' => craft\commerce\elements\Product, 'variables' => ['product' => craft\commerce\elements\Product]]) 18. in /var/www/html/vendor/craftcms/cms/src/web/View.php at line 488– [Twig\Environment::render](http://twig.sensiolabs.org/api/2.x/Twig/Environment.html#method_render)('artikel.twig', ['product' => craft\commerce\elements\Product, 'variables' => ['product' => craft\commerce\elements\Product]]) 482483484485486487488489490491492493494 // Render and return $renderingTemplate = $this->_renderingTemplate; $this->_renderingTemplate = $template; try { $output = $this->getTwig()->render($template, $variables); } finally { $this->_renderingTemplate = $renderingTemplate; $this->setTemplateMode($oldTemplateMode); } $this->afterRenderTemplate($template, $variables, $templateMode, $output); 19. in /var/www/html/vendor/craftcms/cms/src/web/View.php at line 541– craft\web\View::renderTemplate('artikel.twig', ['product' => craft\commerce\elements\Product, 'variables' => ['product' => craft\commerce\elements\Product]]) 535536537538539540541542543544545546547 $isRenderingPageTemplate = $this->_isRenderingPageTemplate; $this->_isRenderingPageTemplate = true; try { $this->beginPage(); echo $this->renderTemplate($template, $variables); $this->endPage(); } finally { $this->_isRenderingPageTemplate = $isRenderingPageTemplate; $this->setTemplateMode($oldTemplateMode); $output = ob_get_clean(); } 20. in /var/www/html/vendor/craftcms/cms/src/web/TemplateResponseFormatter.php at line 57– craft\web\View::renderPageTemplate('artikel.twig', ['product' => craft\commerce\elements\Product, 'variables' => ['product' => craft\commerce\elements\Product]], 'site') 51525354555657585960616263 ) { $view->registerAssetBundle(ContentWindowAsset::class); } // Render and return the template try { $response->content = $view->renderPageTemplate($behavior->template, $behavior->variables, $behavior->templateMode); } catch (Throwable $e) { $previous = $e->getPrevious(); if ($previous instanceof YiiExitException) { // Something called Craft::$app->end() if ($previous instanceof ExitException && $previous->output !== null) { echo $previous->output; 21. in /var/www/html/vendor/yiisoft/yii2/web/Response.php at line 1109– craft\web\TemplateResponseFormatter::format(craft\web\Response) 22. in /var/www/html/vendor/craftcms/cms/src/web/Response.php at line 338– [yii\web\Response::prepare](https://www.yiiframework.com/doc-2.0/yii-web-response.html#prepare()-detail)() 332333334335336337338339340341342343344 /** * @inheritdoc */ protected function prepare(): void { parent::prepare(); $this->_isPrepared = true; } /** * Clear the output buffer to prevent corrupt downloads. * 23. in /var/www/html/vendor/yiisoft/yii2/web/Response.php at line 340– craft\web\Response::prepare() 24. in /var/www/html/vendor/yiisoft/yii2/base/Application.php at line 390– [yii\web\Response::send](https://www.yiiframework.com/doc-2.0/yii-web-response.html#send()-detail)() 25. in /var/www/html/web/index.php at line 12– [yii\base\Application::run](https://www.yiiframework.com/doc-2.0/yii-base-application.html#run()-detail)()
khalwat commented 3 months ago

So I think this is the same as: https://github.com/nystudio107/craft-similar/issues/51

Can you try this update to see how it works for you?

You can try it now by setting your semver in your composer.json to look like this:

    "nystudio107/craft-similar": "dev-develop-v5 as 5.0.1”,

Then do a composer clear-cache && composer update

Let me know how it works out for you!

klick commented 3 months ago

Different error now after changing db collation to utf8mb4_unicode_ci, which I had to do:

Cannot assign null to property craft\commerce\elements\db\ProductQuery::$editable of type bool

After updating similar to

"dev-develop-v5 as 5.0.1”,

as per your suggestion, the above error remained the same.

khalwat commented 3 months ago

Alright, I think I've got it. Addressed in the above commit. Do this again and it should update with the latest changes from the dev-develop-v5 branch, and let me know how you go.

You can try it now by setting your semver in your composer.json to look like this:

    "nystudio107/craft-similar": "dev-develop-v5 as 5.0.1”,

Then do a composer clear-cache && composer update

Let me know how it works out for you!

klick commented 3 months ago

Did that but I get the same error as before:

TypeError Cannot assign null to property craft\commerce\elements\db\ProductQuery::$editable of type bool

khalwat commented 3 months ago

@klick you'll need to give me more context on that error, but it's very possible that this isn't actually an issue with the Similar plugin.

I just can't tell without seeing the full stack trace from the error... and the stack trace you posted earlier seems like it is different from this one? (nowhere in the stack trace you posted does it show TypeError)

khalwat commented 3 months ago

I've released version 5.0.1 -> https://github.com/nystudio107/craft-similar/releases/tag/5.0.1

Which fixes two verified, legit bugs. If there are more issues you find after updating to that version, I can continue to work with you on them.

klick commented 3 months ago

Hi Andrew.

I have upgraded to 5.0.1 and it still gives me the above error. It’s entirely possible that similar might not be the problem though this happens on a fresh install in a new ddev container. So that makes it hard to identify legacy issues.

Full Error code:

TypeError
Cannot assign null to property craft\commerce\elements\db\ProductQuery::$editable of type bool
1. in /var/www/html/vendor/yiisoft/yii2/BaseYii.phpat line 557
548549550551552553554555556557558559560561562563564565566    /**
     * Configures an object with the initial property values.
     * @param object $object the object to be configured
     * @param array $properties the property initial values given in terms of name-value pairs.
     * @return object the object itself
     */
    public static function configure($object, $properties)
    {
        foreach ($properties as $name => $value) {
            $object->$name = $value;
        }

        return $object;
    }

    /**
     * Returns the public member variables of an object.
     * This method is provided such that we can get the public member variables of an object.
     * It is different from "get_object_vars()" because the latter will return private
2. in /var/www/html/vendor/nystudio107/craft-similar/src/services/Similar.php at line 229– [yii\BaseYii::configure](https://www.yiiframework.com/doc-2.0/yii-baseyii.html#configure()-detail)(craft\commerce\elements\db\ProductQuery, ['select' => ['**' => '**'], 'selectOption' => null, 'distinct' => false, 'from' => null, ...])
223224225226227228229230231232233     * @return ElementQueryInterface
     */
    protected function getElementQuery(string|ElementInterface $elementType, array $criteria): ElementQueryInterface
    {
        /** @var string|ElementInterface $elementType */
        $query = $elementType::find();
        Craft::configure($query, $criteria);

        return $query;
    }
}
3. in /var/www/html/vendor/nystudio107/craft-similar/src/services/Similar.php at line 85– nystudio107\similar\services\Similar::getElementQuery('craft\commerce\elements\Product', ['select' => ['**' => '**'], 'selectOption' => null, 'distinct' => false, 'from' => null, ...])
79808182838485868788899091            $criteria = $criteria->toArray();
        }

        // Get an ElementQuery for this Element
        $elementClass = is_object($element) ? $element::class : $element;
        /** @var EntryQuery $query */
        $query = $this->getElementQuery($elementClass, $criteria);

        // Stash any orderBy directives from the $query for our anonymous function
        $this->preOrder = $query->orderBy ?? [];
        $this->limit = $query->limit;
        // Extract the $tagIds from the $context
        if (is_array($context)) {
4. in /var/www/html/vendor/nystudio107/craft-similar/src/variables/SimilarVariable.php at line 35– nystudio107\similar\services\Similar::find(['element' => craft\commerce\elements\Product, 'context' => craft\elements\db\TagQuery, 'criteria' => craft\elements\db\EntryQuery])
293031323334353637     *
     * @return array|ElementInterface
     * @throws Exception
     */
    public function find(array $data): array|ElementInterface
    {
        return Similar::$plugin->similar->find($data);
    }
}
5. in /var/www/html/vendor/twig/twig/src/Extension/CoreExtension.php at line 1635– nystudio107\similar\variables\SimilarVariable::find(['element' => craft\commerce\elements\Product, 'context' => craft\elements\db\TagQuery, 'criteria' => craft\elements\db\EntryQuery])
6. in /var/www/html/vendor/craftcms/cms/src/helpers/Template.php at line 141– twig_get_attribute(craft\web\twig\Environment, Twig\Source, nystudio107\similar\variables\SimilarVariable, 'find', ...)
135136137138139140141142143144145146147            if (is_object($value) && get_class($value) === Markup::class) {
                $arguments[$key] = (string)$value;
            }
        }

        try {
            return twig_get_attribute(
                $env,
                $source,
                $object,
                $item,
                $arguments,
                $type,
7. in /var/www/html/templates/artikel.twig at line 4– craft\helpers\Template::attribute(craft\web\twig\Environment, Twig\Source, nystudio107\similar\variables\SimilarVariable, 'find', ...)
12345678910{% extends '_layout' %}
{% set cart = craft.commerce.carts.cart %}
{% set limitCriteria = craft.entries().limit(4) %}
{% set similarProductsByTags = craft.similar.find({ element: product, context: product.tags, criteria: limitCriteria }) %}

{% set variants = product.getVariants() %}

{% block content %}
<div class="container">
    <div class="row">
8. in /var/www/html/vendor/twig/twig/src/Template.php at line 394– [__TwigTemplate_0679d112917587150eefd6fc863d181a::doDisplay](http://twig.sensiolabs.org/api/2.x/Twig/Template.html#method_doDisplay)(['product' => craft\commerce\elements\Product, 'variables' => ['product' => craft\commerce\elements\Product], 'craft' => craft\web\twig\variables\CraftVariable, 'currentSite' => craft\models\Site, ...], ['content' => [__TwigTemplate_0679d112917587150eefd6fc863d181a, 'block_content']])
9. in /var/www/html/vendor/twig/twig/src/Template.php at line 367– [Twig\Template::displayWithErrorHandling](http://twig.sensiolabs.org/api/2.x/Twig/Template.html#method_displayWithErrorHandling)(['product' => craft\commerce\elements\Product, 'variables' => ['product' => craft\commerce\elements\Product], 'craft' => craft\web\twig\variables\CraftVariable, 'currentSite' => craft\models\Site, ...], ['content' => [__TwigTemplate_0679d112917587150eefd6fc863d181a, 'block_content']])
10. in /var/www/html/vendor/twig/twig/src/Template.php at line 379– [Twig\Template::display](http://twig.sensiolabs.org/api/2.x/Twig/Template.html#method_display)(['product' => craft\commerce\elements\Product, 'variables' => ['product' => craft\commerce\elements\Product]])
11. in /var/www/html/vendor/twig/twig/src/TemplateWrapper.php at line 38– [Twig\Template::render](http://twig.sensiolabs.org/api/2.x/Twig/Template.html#method_render)(['product' => craft\commerce\elements\Product, 'variables' => ['product' => craft\commerce\elements\Product]])
12. in /var/www/html/vendor/twig/twig/src/Environment.php at line 280– [Twig\TemplateWrapper::render](http://twig.sensiolabs.org/api/2.x/Twig/TemplateWrapper.html#method_render)(['product' => craft\commerce\elements\Product, 'variables' => ['product' => craft\commerce\elements\Product]])
13. in /var/www/html/vendor/craftcms/cms/src/web/View.php at line 494– [Twig\Environment::render](http://twig.sensiolabs.org/api/2.x/Twig/Environment.html#method_render)('artikel.twig', ['product' => craft\commerce\elements\Product, 'variables' => ['product' => craft\commerce\elements\Product]])
488489490491492493494495496497498499500 
        // Render and return
        $renderingTemplate = $this->_renderingTemplate;
        $this->_renderingTemplate = $template;

        try {
            $output = $this->getTwig()->render($template, $variables);
        } finally {
            $this->_renderingTemplate = $renderingTemplate;
            $this->setTemplateMode($oldTemplateMode);
        }

        $this->afterRenderTemplate($template, $variables, $templateMode, $output);
14. in /var/www/html/vendor/craftcms/cms/src/web/View.php at line 547– craft\web\View::renderTemplate('artikel.twig', ['product' => craft\commerce\elements\Product, 'variables' => ['product' => craft\commerce\elements\Product]])
541542543544545546547548549550551552553 
        $isRenderingPageTemplate = $this->_isRenderingPageTemplate;
        $this->_isRenderingPageTemplate = true;

        try {
            $this->beginPage();
            echo $this->renderTemplate($template, $variables);
            $this->endPage();
        } finally {
            $this->_isRenderingPageTemplate = $isRenderingPageTemplate;
            $this->setTemplateMode($oldTemplateMode);
            $output = ob_get_clean();
        }
15. in /var/www/html/vendor/craftcms/cms/src/web/TemplateResponseFormatter.php at line 57– craft\web\View::renderPageTemplate('artikel.twig', ['product' => craft\commerce\elements\Product, 'variables' => ['product' => craft\commerce\elements\Product]], 'site')
51525354555657585960616263        ) {
            $view->registerAssetBundle(ContentWindowAsset::class);
        }

        // Render and return the template
        try {
            $response->content = $view->renderPageTemplate($behavior->template, $behavior->variables, $behavior->templateMode);
        } catch (Throwable $e) {
            $previous = $e->getPrevious();
            if ($previous instanceof YiiExitException) {
                // Something called Craft::$app->end()
                if ($previous instanceof ExitException && $previous->output !== null) {
                    echo $previous->output;
16. in /var/www/html/vendor/yiisoft/yii2/web/Response.php at line 1109– craft\web\TemplateResponseFormatter::format(craft\web\Response)
17. in /var/www/html/vendor/craftcms/cms/src/web/Response.php at line 338– [yii\web\Response::prepare](https://www.yiiframework.com/doc-2.0/yii-web-response.html#prepare()-detail)()
332333334335336337338339340341342343344 
    /**
     * @inheritdoc
     */
    protected function prepare(): void
    {
        parent::prepare();
        $this->_isPrepared = true;
    }

    /**
     * Clear the output buffer to prevent corrupt downloads.
     *
18. in /var/www/html/vendor/yiisoft/yii2/web/Response.php at line 340– craft\web\Response::prepare()
19. in /var/www/html/vendor/yiisoft/yii2/base/Application.php at line 390– [yii\web\Response::send](https://www.yiiframework.com/doc-2.0/yii-web-response.html#send()-detail)()
20. in /var/www/html/web/index.php at line 12– [yii\base\Application::run](https://www.yiiframework.com/doc-2.0/yii-base-application.html#run()-detail)()
6789101112// Load shared bootstrap
require dirname(__DIR__) . '/bootstrap.php';

// Load and run Craft
/** @var craft\web\Application $app */
$app = require CRAFT_VENDOR_PATH . '/craftcms/cms/bootstrap/web.php';
$app->run();
klick commented 3 months ago

Thanks Andrew. Did the upgrade to 5.0.2 and also the Craft and ddev update which all referenced db issues but still get the same error:

TypeError
Cannot assign null to property craft\commerce\elements\db\ProductQuery::$editable of type bool

Maybe my installation is cursed? ;) I wish I could be of more help but my knowledge of mysql is very limited. :\

Full error message:

TypeError
Cannot assign null to property craft\commerce\elements\db\ProductQuery::$editable of type bool
1. in /var/www/html/vendor/yiisoft/yii2/BaseYii.phpat line 557
548549550551552553554555556557558559560561562563564565566    /**
     * Configures an object with the initial property values.
     * @param object $object the object to be configured
     * @param array $properties the property initial values given in terms of name-value pairs.
     * @return object the object itself
     */
    public static function configure($object, $properties)
    {
        foreach ($properties as $name => $value) {
            $object->$name = $value;
        }

        return $object;
    }

    /**
     * Returns the public member variables of an object.
     * This method is provided such that we can get the public member variables of an object.
     * It is different from "get_object_vars()" because the latter will return private
2. in /var/www/html/vendor/nystudio107/craft-similar/src/services/Similar.php at line 229– [yii\BaseYii::configure](https://www.yiiframework.com/doc-2.0/yii-baseyii.html#configure()-detail)(craft\commerce\elements\db\ProductQuery, ['select' => ['**' => '**'], 'selectOption' => null, 'distinct' => false, 'from' => null, ...])
223224225226227228229230231232233     * @return ElementQueryInterface
     */
    protected function getElementQuery(string|ElementInterface $elementType, array $criteria): ElementQueryInterface
    {
        /** @var string|ElementInterface $elementType */
        $query = $elementType::find();
        Craft::configure($query, $criteria);

        return $query;
    }
}
3. in /var/www/html/vendor/nystudio107/craft-similar/src/services/Similar.php at line 85– nystudio107\similar\services\Similar::getElementQuery('craft\commerce\elements\Product', ['select' => ['**' => '**'], 'selectOption' => null, 'distinct' => false, 'from' => null, ...])
79808182838485868788899091            $criteria = $criteria->toArray([], [], false);
        }

        // Get an ElementQuery for this Element
        $elementClass = is_object($element) ? $element::class : $element;
        /** @var EntryQuery $query */
        $query = $this->getElementQuery($elementClass, $criteria);

        // Stash any orderBy directives from the $query for our anonymous function
        $this->preOrder = $query->orderBy ?? [];
        $this->limit = $query->limit;
        // Extract the $tagIds from the $context
        if (is_array($context)) {
4. in /var/www/html/vendor/nystudio107/craft-similar/src/variables/SimilarVariable.php at line 35– nystudio107\similar\services\Similar::find(['element' => craft\commerce\elements\Product, 'context' => craft\elements\db\TagQuery, 'criteria' => craft\elements\db\EntryQuery])
293031323334353637     *
     * @return array|ElementInterface
     * @throws Exception
     */
    public function find(array $data): array|ElementInterface
    {
        return Similar::$plugin->similar->find($data);
    }
}
5. in /var/www/html/vendor/twig/twig/src/Extension/CoreExtension.php at line 1635– nystudio107\similar\variables\SimilarVariable::find(['element' => craft\commerce\elements\Product, 'context' => craft\elements\db\TagQuery, 'criteria' => craft\elements\db\EntryQuery])
6. in /var/www/html/vendor/craftcms/cms/src/helpers/Template.php at line 141– twig_get_attribute(craft\web\twig\Environment, Twig\Source, nystudio107\similar\variables\SimilarVariable, 'find', ...)
135136137138139140141142143144145146147            if (is_object($value) && get_class($value) === Markup::class) {
                $arguments[$key] = (string)$value;
            }
        }

        try {
            return twig_get_attribute(
                $env,
                $source,
                $object,
                $item,
                $arguments,
                $type,
7. in /var/www/html/templates/artikel.twig at line 4– craft\helpers\Template::attribute(craft\web\twig\Environment, Twig\Source, nystudio107\similar\variables\SimilarVariable, 'find', ...)
12345678910{% extends '_layout' %}
{% set cart = craft.commerce.carts.cart %}
{% set limitCriteria = craft.entries().limit(4) %}
{% set similarProductsByTags = craft.similar.find({ element: product, context: product.tags, criteria: limitCriteria }) %}

{% set variants = product.getVariants() %}

{% block content %}
<div class="container">
    <div class="row">
8. in /var/www/html/vendor/twig/twig/src/Template.php at line 394– [__TwigTemplate_0679d112917587150eefd6fc863d181a::doDisplay](http://twig.sensiolabs.org/api/2.x/Twig/Template.html#method_doDisplay)(['product' => craft\commerce\elements\Product, 'variables' => ['product' => craft\commerce\elements\Product], 'craft' => craft\web\twig\variables\CraftVariable, 'currentSite' => craft\models\Site, ...], ['content' => [__TwigTemplate_0679d112917587150eefd6fc863d181a, 'block_content']])
9. in /var/www/html/vendor/twig/twig/src/Template.php at line 367– [Twig\Template::displayWithErrorHandling](http://twig.sensiolabs.org/api/2.x/Twig/Template.html#method_displayWithErrorHandling)(['product' => craft\commerce\elements\Product, 'variables' => ['product' => craft\commerce\elements\Product], 'craft' => craft\web\twig\variables\CraftVariable, 'currentSite' => craft\models\Site, ...], ['content' => [__TwigTemplate_0679d112917587150eefd6fc863d181a, 'block_content']])
10. in /var/www/html/vendor/twig/twig/src/Template.php at line 379– [Twig\Template::display](http://twig.sensiolabs.org/api/2.x/Twig/Template.html#method_display)(['product' => craft\commerce\elements\Product, 'variables' => ['product' => craft\commerce\elements\Product]])
11. in /var/www/html/vendor/twig/twig/src/TemplateWrapper.php at line 38– [Twig\Template::render](http://twig.sensiolabs.org/api/2.x/Twig/Template.html#method_render)(['product' => craft\commerce\elements\Product, 'variables' => ['product' => craft\commerce\elements\Product]])
12. in /var/www/html/vendor/twig/twig/src/Environment.php at line 280– [Twig\TemplateWrapper::render](http://twig.sensiolabs.org/api/2.x/Twig/TemplateWrapper.html#method_render)(['product' => craft\commerce\elements\Product, 'variables' => ['product' => craft\commerce\elements\Product]])
13. in /var/www/html/vendor/craftcms/cms/src/web/View.php at line 494– [Twig\Environment::render](http://twig.sensiolabs.org/api/2.x/Twig/Environment.html#method_render)('artikel.twig', ['product' => craft\commerce\elements\Product, 'variables' => ['product' => craft\commerce\elements\Product]])
488489490491492493494495496497498499500 
        // Render and return
        $renderingTemplate = $this->_renderingTemplate;
        $this->_renderingTemplate = $template;

        try {
            $output = $this->getTwig()->render($template, $variables);
        } finally {
            $this->_renderingTemplate = $renderingTemplate;
            $this->setTemplateMode($oldTemplateMode);
        }

        $this->afterRenderTemplate($template, $variables, $templateMode, $output);
14. in /var/www/html/vendor/craftcms/cms/src/web/View.php at line 547– craft\web\View::renderTemplate('artikel.twig', ['product' => craft\commerce\elements\Product, 'variables' => ['product' => craft\commerce\elements\Product]])
541542543544545546547548549550551552553 
        $isRenderingPageTemplate = $this->_isRenderingPageTemplate;
        $this->_isRenderingPageTemplate = true;

        try {
            $this->beginPage();
            echo $this->renderTemplate($template, $variables);
            $this->endPage();
        } finally {
            $this->_isRenderingPageTemplate = $isRenderingPageTemplate;
            $this->setTemplateMode($oldTemplateMode);
            $output = ob_get_clean();
        }
15. in /var/www/html/vendor/craftcms/cms/src/web/TemplateResponseFormatter.php at line 57– craft\web\View::renderPageTemplate('artikel.twig', ['product' => craft\commerce\elements\Product, 'variables' => ['product' => craft\commerce\elements\Product]], 'site')
51525354555657585960616263        ) {
            $view->registerAssetBundle(ContentWindowAsset::class);
        }

        // Render and return the template
        try {
            $response->content = $view->renderPageTemplate($behavior->template, $behavior->variables, $behavior->templateMode);
        } catch (Throwable $e) {
            $previous = $e->getPrevious();
            if ($previous instanceof YiiExitException) {
                // Something called Craft::$app->end()
                if ($previous instanceof ExitException && $previous->output !== null) {
                    echo $previous->output;
16. in /var/www/html/vendor/yiisoft/yii2/web/Response.php at line 1109– craft\web\TemplateResponseFormatter::format(craft\web\Response)
17. in /var/www/html/vendor/craftcms/cms/src/web/Response.php at line 338– [yii\web\Response::prepare](https://www.yiiframework.com/doc-2.0/yii-web-response.html#prepare()-detail)()
332333334335336337338339340341342343344 
    /**
     * @inheritdoc
     */
    protected function prepare(): void
    {
        parent::prepare();
        $this->_isPrepared = true;
    }

    /**
     * Clear the output buffer to prevent corrupt downloads.
     *
18. in /var/www/html/vendor/yiisoft/yii2/web/Response.php at line 340– craft\web\Response::prepare()
19. in /var/www/html/vendor/yiisoft/yii2/base/Application.php at line 390– [yii\web\Response::send](https://www.yiiframework.com/doc-2.0/yii-web-response.html#send()-detail)()
20. in /var/www/html/web/index.php at line 12– [yii\base\Application::run](https://www.yiiframework.com/doc-2.0/yii-base-application.html#run()-detail)()
6789101112// Load shared bootstrap
require dirname(__DIR__) . '/bootstrap.php';

// Load and run Craft
/** @var craft\web\Application $app */
$app = require CRAFT_VENDOR_PATH . '/craftcms/cms/bootstrap/web.php';
$app->run();
klick commented 3 months ago

So I have just changed my criteria from

{% set limitCriteria = craft.entries().limit(4) %}

to

{% set limitCriteria = craft.products().limit(4) %}

which obviously was wrong.

Now works as expected. Thanks Andrew! Much appreciated.