craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.28k stars 635 forks source link

[5.x]: Setting unknown property: craft\elements\Category::COUNT(*) #15071

Closed cballenar closed 5 months ago

cballenar commented 5 months ago

What happened?

Description

This came up while upgrading from 4.8.4 to 5.1.6 It did not come up in development and it does not seem appear in all pages so I'm quite baffled by this one. We had to roll it back as we couldn't find a solution.

The only error that seems to get logged is the following:

2024-05-25 07:02:43 [web.ERROR] [yii\base\UnknownPropertyException] Setting unknown property: craft\elements\Category::COUNT(*) {"trace":[
    "#0 /srv/example/example.com/vendor/craftcms/cms/src/base/Element.php(2277): yii\\base\\Component->__set()",
    "#1 /srv/example/example.com/vendor/yiisoft/yii2/BaseYii.php(558): craft\\base\\Element->__set()",
    "#2 /srv/example/example.com/vendor/yiisoft/yii2/base/BaseObject.php(107): yii\\BaseYii::configure()",
    "#3 /srv/example/example.com/vendor/craftcms/cms/src/base/Model.php(78): yii\\base\\BaseObject->__construct()",
    "#4 /srv/example/example.com/vendor/craftcms/cms/src/base/Element.php(2182): craft\\base\\Model->__construct()",
    "#5 /srv/example/example.com/vendor/craftcms/cms/src/elements/db/ElementQuery.php(2232): craft\\base\\Element->__construct()",
    "#6 /srv/example/example.com/vendor/craftcms/cms/src/elements/db/ElementQuery.php(3373): craft\\elements\\db\\ElementQuery->createElement()",
    "#7 /srv/example/example.com/vendor/craftcms/cms/src/elements/db/ElementQuery.php(1666): craft\\elements\\db\\ElementQuery->_createElements()",
    "#8 /srv/example/example.com/vendor/yiisoft/yii2/db/Query.php(251): craft\\elements\\db\\ElementQuery->populate()",
    "#9 /srv/example/example.com/vendor/craftcms/cms/src/db/Query.php(247): yii\\db\\Query->all()",
    "#10 /srv/example/example.com/vendor/craftcms/cms/src/elements/db/ElementQuery.php(1739): craft\\db\\Query->all()",
    "#11 /srv/example/example.com/vendor/craftcms/cms/src/fields/BaseRelationField.php(659): craft\\elements\\db\\ElementQuery->all()",
    "#12 /srv/example/example.com/vendor/craftcms/cms/src/behaviors/EventBehavior.php(58): craft\\fields\\BaseRelationField->craft\\fields\\{closure}()",
    "#13 /srv/example/example.com/vendor/craftcms/cms/src/behaviors/EventBehavior.php(43): craft\\behaviors\\EventBehavior->handleEvent()",
    "#14 [internal function]: craft\\behaviors\\EventBehavior->craft\\behaviors\\{closure}()",
    "#15 /srv/example/example.com/vendor/yiisoft/yii2/base/Component.php(633): call_user_func()",
    "#16 /srv/example/example.com/vendor/craftcms/cms/src/elements/db/ElementQuery.php(2267): yii\\base\\Component->trigger()",
    "#17 /srv/example/example.com/vendor/craftcms/cms/src/elements/db/CategoryQuery.php(200): craft\\elements\\db\\ElementQuery->beforePrepare()",
    "#18 /srv/example/example.com/vendor/craftcms/cms/src/elements/db/ElementQuery.php(1506): craft\\elements\\db\\CategoryQuery->beforePrepare()",
    "#19 /srv/example/example.com/vendor/craftcms/cms/src/elements/db/ElementQuery.php(2020): craft\\elements\\db\\ElementQuery->prepare()",
    "#20 /srv/example/example.com/vendor/craftcms/cms/src/elements/db/ElementQuery.php(2054): craft\\elements\\db\\ElementQuery->prepareSubquery()",
    "#21 /srv/example/example.com/vendor/yiisoft/yii2/db/Query.php(368): craft\\elements\\db\\ElementQuery->queryScalar()",
    "#22 /srv/example/example.com/vendor/craftcms/cms/src/elements/db/ElementQuery.php(1722): yii\\db\\Query->count()",
    "#23 /srv/example/example.com/vendor/craftcms/cms/src/web/twig/Extension.php(1234): craft\\elements\\db\\ElementQuery->count()",
    "#24 /srv/example/example.com/storage/runtime/compiled_templates/ed/ed400ca4229d042c90f3c505260d562e.php(71): craft\\web\\twig\\Extension->lengthFilter()",
    "#25 /srv/example/example.com/vendor/twig/twig/src/Template.php(171): __TwigTemplate_ed130ec7e47f0eaf1aa1a2d2b666a4be->block__entry()",
    "#26 /srv/example/example.com/storage/runtime/compiled_templates/ed/ed400ca4229d042c90f3c505260d562e.php(39): Twig\\Template->displayBlock()",
    "#27 /srv/example/example.com/vendor/twig/twig/src/Template.php(394): __TwigTemplate_ed130ec7e47f0eaf1aa1a2d2b666a4be->doDisplay()",
    "#28 /srv/example/example.com/vendor/twig/twig/src/Template.php(367): Twig\\Template->displayWithErrorHandling()",
    "#29 /srv/example/example.com/storage/runtime/compiled_templates/7a/7a72fceb48c563c618e5c64f4c1db372.php(458): Twig\\Template->display()",
    "#30 /srv/example/example.com/vendor/twig/twig/src/Template.php(394): __TwigTemplate_7a5df1786bbdd6b6aa71d087e77fa050___1069494657->doDisplay()",
    "#31 /srv/example/example.com/vendor/twig/twig/src/Template.php(367): Twig\\Template->displayWithErrorHandling()",
    "#32 /srv/example/example.com/storage/runtime/compiled_templates/7a/7a72fceb48c563c618e5c64f4c1db372.php(354): Twig\\Template->display()",
    "#33 /srv/example/example.com/vendor/twig/twig/src/Template.php(171): __TwigTemplate_7a5df1786bbdd6b6aa71d087e77fa050___725603198->block_mainCol()",
    "#34 /srv/example/example.com/vendor/twig/twig/src/Template.php(243): Twig\\Template->displayBlock()",
    "#35 /srv/example/example.com/storage/runtime/compiled_templates/98/98b9e95f128f37a499d9967820955f50.php(38): Twig\\Template->renderBlock()",
    "#36 /srv/example/example.com/vendor/twig/twig/src/Template.php(394): __TwigTemplate_02d7ca1870f3648d1515d681db27ff0d->doDisplay()",
    "#37 /srv/example/example.com/vendor/twig/twig/src/Template.php(367): Twig\\Template->displayWithErrorHandling()",
    "#38 /srv/example/example.com/storage/runtime/compiled_templates/7a/7a72fceb48c563c618e5c64f4c1db372.php(280): Twig\\Template->display()",
    "#39 /srv/example/example.com/vendor/twig/twig/src/Template.php(394): __TwigTemplate_7a5df1786bbdd6b6aa71d087e77fa050___725603198->doDisplay()",
    "#40 /srv/example/example.com/vendor/twig/twig/src/Template.php(367): Twig\\Template->displayWithErrorHandling()",
    "#41 /srv/example/example.com/storage/runtime/compiled_templates/7a/7a72fceb48c563c618e5c64f4c1db372.php(150): Twig\\Template->display()",
    "#42 /srv/example/example.com/vendor/twig/twig/src/Template.php(171): __TwigTemplate_7a5df1786bbdd6b6aa71d087e77fa050->block_content()",
    "#43 /srv/example/example.com/storage/runtime/compiled_templates/87/87955593a7681b48e1f38207163efbef.php(407): Twig\\Template->displayBlock()",
    "#44 /srv/example/example.com/vendor/twig/twig/src/Template.php(394): __TwigTemplate_a7c45ffe097f0b174d86b5199cb95d99->doDisplay()",
    "#45 /srv/example/example.com/vendor/twig/twig/src/Template.php(367): Twig\\Template->displayWithErrorHandling()",
    "#46 /srv/example/example.com/storage/runtime/compiled_templates/7a/7a72fceb48c563c618e5c64f4c1db372.php(139): Twig\\Template->display()",
    "#47 /srv/example/example.com/vendor/twig/twig/src/Template.php(394): __TwigTemplate_7a5df1786bbdd6b6aa71d087e77fa050->doDisplay()",
    "#48 /srv/example/example.com/vendor/twig/twig/src/Template.php(367): Twig\\Template->displayWithErrorHandling()",
    "#49 /srv/example/example.com/vendor/twig/twig/src/Template.php(379): Twig\\Template->display()",
    "#50 /srv/example/example.com/vendor/twig/twig/src/TemplateWrapper.php(38): Twig\\Template->render()",
    "#51 /srv/example/example.com/vendor/twig/twig/src/Environment.php(280): Twig\\TemplateWrapper->render()",
    "#52 /srv/example/example.com/vendor/craftcms/cms/src/web/View.php(482): Twig\\Environment->render()",
    "#53 /srv/example/example.com/vendor/craftcms/cms/src/web/View.php(535): craft\\web\\View->renderTemplate()",
    "#54 /srv/example/example.com/vendor/craftcms/cms/src/web/TemplateResponseFormatter.php(57): craft\\web\\View->renderPageTemplate()",
    "#55 /srv/example/example.com/vendor/yiisoft/yii2/web/Response.php(1100): craft\\web\\TemplateResponseFormatter->format()",
    "#56 /srv/example/example.com/vendor/craftcms/cms/src/web/Response.php(338): yii\\web\\Response->prepare()",
    "#57 /srv/example/example.com/vendor/yiisoft/yii2/web/Response.php(340): craft\\web\\Response->prepare()",
    "#58 /srv/example/example.com/vendor/yiisoft/yii2/base/Application.php(390): yii\\web\\Response->send()",
    "#59 /srv/example/example.com/web/index.php(12): yii\\base\\Application->run()",
    "#60 {main}"
],"memory":6147504,"exception":"[object] (yii\\base\\UnknownPropertyException(code: 0): Setting unknown property: craft\\elements\\Category::COUNT(*) at /srv/example/example.com/vendor/yiisoft/yii2/base/Component.php:209)"} 

2024-05-25 07:35:33 [web.ERROR] [yii\base\UnknownPropertyException] Setting unknown property: craft\elements\Category::COUNT(*) {"trace":[
    "#0 /srv/example/example.com/vendor/craftcms/cms/src/base/Element.php(2277): yii\\base\\Component->__set()",
    "#1 /srv/example/example.com/vendor/yiisoft/yii2/BaseYii.php(558): craft\\base\\Element->__set()",
    "#2 /srv/example/example.com/vendor/yiisoft/yii2/base/BaseObject.php(107): yii\\BaseYii::configure()",
    "#3 /srv/example/example.com/vendor/craftcms/cms/src/base/Model.php(78): yii\\base\\BaseObject->__construct()",
    "#4 /srv/example/example.com/vendor/craftcms/cms/src/base/Element.php(2182): craft\\base\\Model->__construct()",
    "#5 /srv/example/example.com/vendor/craftcms/cms/src/elements/db/ElementQuery.php(2232): craft\\base\\Element->__construct()",
    "#6 /srv/example/example.com/vendor/craftcms/cms/src/elements/db/ElementQuery.php(3373): craft\\elements\\db\\ElementQuery->createElement()",
    "#7 /srv/example/example.com/vendor/craftcms/cms/src/elements/db/ElementQuery.php(1666): craft\\elements\\db\\ElementQuery->_createElements()",
    "#8 /srv/example/example.com/vendor/yiisoft/yii2/db/Query.php(251): craft\\elements\\db\\ElementQuery->populate()",
    "#9 /srv/example/example.com/vendor/craftcms/cms/src/db/Query.php(247): yii\\db\\Query->all()",
    "#10 /srv/example/example.com/vendor/craftcms/cms/src/elements/db/ElementQuery.php(1739): craft\\db\\Query->all()",
    "#11 /srv/example/example.com/vendor/craftcms/cms/src/fields/BaseRelationField.php(659): craft\\elements\\db\\ElementQuery->all()",
    "#12 /srv/example/example.com/vendor/craftcms/cms/src/behaviors/EventBehavior.php(58): craft\\fields\\BaseRelationField->craft\\fields\\{closure}()",
"#13 /srv/example/example.com/vendor/craftcms/cms/src/behaviors/EventBehavior.php(43): craft\\behaviors\\EventBehavior->handleEvent()",
"#14 [internal function]: craft\\behaviors\\EventBehavior->craft\\behaviors\\{closure}()",
"#15 /srv/example/example.com/vendor/yiisoft/yii2/base/Component.php(633): call_user_func()",
"#16 /srv/example/example.com/vendor/craftcms/cms/src/elements/db/ElementQuery.php(2267): yii\\base\\Component->trigger()",
"#17 /srv/example/example.com/vendor/craftcms/cms/src/elements/db/CategoryQuery.php(200): craft\\elements\\db\\ElementQuery->beforePrepare()",
"#18 /srv/example/example.com/vendor/craftcms/cms/src/elements/db/ElementQuery.php(1506): craft\\elements\\db\\CategoryQuery->beforePrepare()",
"#19 /srv/example/example.com/vendor/craftcms/cms/src/elements/db/ElementQuery.php(2020): craft\\elements\\db\\ElementQuery->prepare()",
"#20 /srv/example/example.com/vendor/craftcms/cms/src/elements/db/ElementQuery.php(2054): craft\\elements\\db\\ElementQuery->prepareSubquery()",
"#21 /srv/example/example.com/vendor/yiisoft/yii2/db/Query.php(368): craft\\elements\\db\\ElementQuery->queryScalar()",
"#22 /srv/example/example.com/vendor/craftcms/cms/src/elements/db/ElementQuery.php(1722): yii\\db\\Query->count()",
"#23 /srv/example/example.com/vendor/craftcms/cms/src/web/twig/Extension.php(1234): craft\\elements\\db\\ElementQuery->count()",
"#24 /srv/example/example.com/storage/runtime/compiled_templates/ed/ed400ca4229d042c90f3c505260d562e.php(71): craft\\web\\twig\\Extension->lengthFilter()",
"#25 /srv/example/example.com/vendor/twig/twig/src/Template.php(171): __TwigTemplate_ed130ec7e47f0eaf1aa1a2d2b666a4be->block__entry()",
"#26 /srv/example/example.com/storage/runtime/compiled_templates/ed/ed400ca4229d042c90f3c505260d562e.php(39): Twig\\Template->displayBlock()",
"#27 /srv/example/example.com/vendor/twig/twig/src/Template.php(394): __TwigTemplate_ed130ec7e47f0eaf1aa1a2d2b666a4be->doDisplay()",
"#28 /srv/example/example.com/vendor/twig/twig/src/Template.php(367): Twig\\Template->displayWithErrorHandling()",
"#29 /srv/example/example.com/storage/runtime/compiled_templates/7a/7a72fceb48c563c618e5c64f4c1db372.php(458): Twig\\Template->display()",
"#30 /srv/example/example.com/vendor/twig/twig/src/Template.php(394): __TwigTemplate_7a5df1786bbdd6b6aa71d087e77fa050___993516183->doDisplay()",
"#31 /srv/example/example.com/vendor/twig/twig/src/Template.php(367): Twig\\Template->displayWithErrorHandling()",
"#32 /srv/example/example.com/storage/runtime/compiled_templates/7a/7a72fceb48c563c618e5c64f4c1db372.php(354): Twig\\Template->display()",
"#33 /srv/example/example.com/vendor/twig/twig/src/Template.php(171): __TwigTemplate_7a5df1786bbdd6b6aa71d087e77fa050___1704404264->block_mainCol()",
"#34 /srv/example/example.com/vendor/twig/twig/src/Template.php(243): Twig\\Template->displayBlock()",
"#35 /srv/example/example.com/storage/runtime/compiled_templates/98/98b9e95f128f37a499d9967820955f50.php(38): Twig\\Template->renderBlock()",
"#36 /srv/example/example.com/vendor/twig/twig/src/Template.php(394): __TwigTemplate_02d7ca1870f3648d1515d681db27ff0d->doDisplay()",
"#37 /srv/example/example.com/vendor/twig/twig/src/Template.php(367): Twig\\Template->displayWithErrorHandling()",
"#38 /srv/example/example.com/storage/runtime/compiled_templates/7a/7a72fceb48c563c618e5c64f4c1db372.php(280): Twig\\Template->display()",
"#39 /srv/example/example.com/vendor/twig/twig/src/Template.php(394): __TwigTemplate_7a5df1786bbdd6b6aa71d087e77fa050___1704404264->doDisplay()",
"#40 /srv/example/example.com/vendor/twig/twig/src/Template.php(367): Twig\\Template->displayWithErrorHandling()",
"#41 /srv/example/example.com/storage/runtime/compiled_templates/7a/7a72fceb48c563c618e5c64f4c1db372.php(150): Twig\\Template->display()",
"#42 /srv/example/example.com/vendor/twig/twig/src/Template.php(171): __TwigTemplate_7a5df1786bbdd6b6aa71d087e77fa050->block_content()",
"#43 /srv/example/example.com/storage/runtime/compiled_templates/87/87955593a7681b48e1f38207163efbef.php(407): Twig\\Template->displayBlock()",
"#44 /srv/example/example.com/vendor/twig/twig/src/Template.php(394): __TwigTemplate_a7c45ffe097f0b174d86b5199cb95d99->doDisplay()",
"#45 /srv/example/example.com/vendor/twig/twig/src/Template.php(367): Twig\\Template->displayWithErrorHandling()",
"#46 /srv/example/example.com/storage/runtime/compiled_templates/7a/7a72fceb48c563c618e5c64f4c1db372.php(139): Twig\\Template->display()",
"#47 /srv/example/example.com/vendor/twig/twig/src/Template.php(394): __TwigTemplate_7a5df1786bbdd6b6aa71d087e77fa050->doDisplay()",
"#48 /srv/example/example.com/vendor/twig/twig/src/Template.php(367): Twig\\Template->displayWithErrorHandling()",
"#49 /srv/example/example.com/vendor/twig/twig/src/Template.php(379): Twig\\Template->display()",
"#50 /srv/example/example.com/vendor/twig/twig/src/TemplateWrapper.php(38): Twig\\Template->render()",
"#51 /srv/example/example.com/vendor/twig/twig/src/Environment.php(280): Twig\\TemplateWrapper->render()",
"#52 /srv/example/example.com/vendor/craftcms/cms/src/web/View.php(482): Twig\\Environment->render()",
"#53 /srv/example/example.com/vendor/craftcms/cms/src/web/View.php(535): craft\\web\\View->renderTemplate()",
"#54 /srv/example/example.com/vendor/craftcms/cms/src/web/TemplateResponseFormatter.php(57): craft\\web\\View->renderPageTemplate()",
"#55 /srv/example/example.com/vendor/yiisoft/yii2/web/Response.php(1100): craft\\web\\TemplateResponseFormatter->format()",
"#56 /srv/example/example.com/vendor/craftcms/cms/src/web/Response.php(338): yii\\web\\Response->prepare()",
"#57 /srv/example/example.com/vendor/yiisoft/yii2/web/Response.php(340): craft\\web\\Response->prepare()",
"#58 /srv/example/example.com/vendor/yiisoft/yii2/base/Application.php(390): yii\\web\\Response->send()",
"#59 /srv/example/example.com/web/index.php(12): yii\\base\\Application->run()",
"#60 {main}"],"memory":6504552,"exception":"[object] (yii\\base\\UnknownPropertyException(code: 0): Setting unknown property: craft\\elements\\Category::COUNT(*) at /srv/example/example.com/vendor/yiisoft/yii2/base/Component.php:209)"}

Anyone else seen this? Any pointers? Any other information I could try to find to troubleshoot this?

Thanks!

Craft CMS version

5.1.6

PHP version

8.3

Operating system and version

Debian GNU/Linux 11 (bullseye)

Database type and version

MariaDB 10.7.3

Image driver and version

No response

Installed plugins and versions

"craftcms/ckeditor": "4.0.6", "craftcms/cms": "5.1.6", "craftcms/google-cloud": "^2.2.0", "craftcms/postmark": "^3.1.0", "doublesecretagency/craft-adwizard": "dev-feature/track-views-via-js", "ether/simplemap": "^5.0.0", "nystudio107/craft-vite": "^5.0.0", "putyourlightson/craft-cloudflare": "^3.0.0", "rias/craft-position-fieldtype": "^5.0.0", "spacecatninja/imager-x": "^5.0.0", "spicyweb/craft-embedded-assets": "^5.1.0", "verbb/smith": "3.0.0", "vlucas/phpdotenv": "^5.4.0", "yiisoft/yii2-redis": "^2.0"

brandonkelly commented 5 months ago

Thanks for reporting that! I was able to reproduce when running a count() query on a Categories field’s value, and just tagged Craft 5.1.7 with a fix.

cballenar commented 5 months ago

Awesome! Thanks so much!