Closed kerrig closed 7 months ago
Could you please clear and flush the cache to ensure that nothing is leftover from the previous version and then retest? If that doesn’t help, please send a dump of the blitz_elementqueries
database table to support@putyourlightson.com so I can check whether there are any improperly formatted queries.
@bencroker Thanks so much! Flushing the cache was the key.
I could've sworn we did that during our thrashing but apparently not, we just weren't sure where the root of the issue was, totally makes sense though that there was some old data hanging around.
Glad to hear that solved it!
@bencroker So unfortunately this is still happening. I thought flushing fixed it, and it seems to but only temporarily. It seemed to be two entries that are specifically failing/getting stuck but I'm not sure what they have that would cause that.
Attached is a zip of the blitz_elementqueries
table since you mentioned that last time.
Any additional guidance you can provide would be greatly appreciated! blitz_elementqueries.sql.gz
Thanks, that’s helpful. I see lots of unusual element queries in the database dump you sent. Can you show me an example of how are you writing your element queries? Especially if doing something custom like specifying select
or query
parameters (craft.entries.select
or craft.entries.query
).
Also, it would be worthwhile updating to the latest version of Blitz, refreshing the cache and retesting, just to rule out something that may have already been fixed.
Apologies for the delayed response. I'm a newcomer to this specific project having these issues but I'm not aware of any custom select or query parameters. Looking in the code for craft.entries.select
or craft.entries.query
doesn't return anything. Here's all of search results for craft.entries
in the code that I can find:
{{ craft.entries({ section: 'hotspots' }).all() |map(hotspot => ({ title: hotspot.title, lat: hotspot.hotspotLocation.lat, lng: hotspot.hotspotLocation.lng, address: hotspot.hotspotLocation.address, state: hotspot.hotspotLocation.parts.state, city: hotspot.hotspotLocation.parts.city, })) |json_encode|e('html_attr') }}
{% set query = craft.entries({ section: 'news', newsType: 'article', newsResidentialOrBusiness: [ 'residential', 'both'] }).limit(50) %}
{% set query = craft.entries({ section: 'news', newsType: 'pressRelease', newsResidentialOrBusiness: [ 'both', 'residential'] }).limit(10) %}
{% set query = craft.entries({ section: 'news', newsType: 'article', newsResidentialOrBusiness: ['both' , 'business'] }).limit(50) %}
{% set query = craft.entries({ section: 'news', newsType: 'pressRelease', newsResidentialOrBusiness: [ 'business', 'both'] }).limit(10) %}
craft.entries({ section: category.section.handle, level: 1, type: 'category' }).all()
{% set root = craft.entries({ section: entry.section.handle ~ 'Page' }).one %}
Only the last one would apply to the pages that are consistently getting stuck/failing. The other thing to mention is this site is mostly built to use one content designer field for majority of the pages. Most of the content on the page is loaded through a macro that looks for a content designer block template.
{% macro renderBlock(block, blockLoop) %}{% apply spaceless %}
{% import _self as macros %}
{% if block.type == 'sharedSection' %}
{% for subblock in block.sharedSection.all() %}
{{ macros.renderAllBlocks(subblock.contentDesigner, loop) }}
{% endfor %}
{% else %}
{% include ['/_components/blocks/' ~ block.type, '/_components/baseSection'] %}
{% endif %}
{% endapply %}{% endmacro %}
{% macro renderAllBlocks(field) %}{% apply spaceless %}
{% import _self as macros %}
{% if field is not null %}
{% for block in field.level(1).all() %}
{{ macros.renderBlock(block, loop) }}
{% endfor %}
{% endif %}
{% endapply %}{% endmacro %}
Is there anything else specific I should try looking for that might be related to the unusual queries you mention? Is there a specific one that you see that you could point out so I can try to track down what templates / code it might be using to see if there's any custom code you mentioned?
I’m unable to reproduce the issue locally and have verified that it works as expected with a unit test. Can you please update to the latest version of Blitz, clear and flush the cache and then see if you can reproduce it?
@bencroker I've updated to the latest version and deployed that to a staging site. It seems as though clearing and flushing the cache works initially but then after it's been sitting for a little bit, the issue pops back up again. I thought it was a couple specific entries that were causing it that I could consistently reproduce the issue with but once I clear and flush the cache it doesn't happen with those entries any more, it starts happening with a different entry.
I suppose the next step is to create a test repo and see if you can reproduce there. If you can then I’m happy to install it locally and troubleshoot from there.
Any update on this, @kerrig?
@bencroker Apologies, been wrapped up in other stuff, will hopefully get you an update by EOW.
Closing due to inactivity. If you'd like me to test using a repo then please send details to support@putyourlightson.com and I'll take a look.
I'm getting this error as well with a similar version of Blitz and Craft:
I've been able to pair the issue down to a repeatable set of steps so I'm happy to supply a codebase/DB export if necessary, @bencroker.
Here's a step-by-step of what I'm doing:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test</title>
</head>
<body>
{{ craft.entries.section('healthWellnessEvent').relatedTo(entry).count() > 0 }}
</body>
</html>
2024-01-30 10:25:00 [80754] Refreshing Blitz cache (attempt: 1, pid: 96807) - Error (0.134 s)
> TypeError: Cannot assign array to property craft\elements\db\ElementQuery::$query of type ?craft\db\Query
Stack trace:
#0 /Users/abushnell/Code/REDACTED/app/vendor/putyourlightson/craft-blitz/src/jobs/RefreshCacheJob.php(162): putyourlightson\blitz\helpers\RefreshCacheHelper::getElementQueryCacheIds(Object(putyourlightson\blitz\records\ElementQueryRecord), Object(putyourlightson\blitz\models\RefreshDataModel))
#1 /Users/abushnell/Code/REDACTED/app/vendor/putyourlightson/craft-blitz/src/jobs/RefreshCacheJob.php(75): putyourlightson\blitz\jobs\RefreshCacheJob->_populateCacheIdsFromElementQueryCaches(Object(putyourlightson\blitz\models\RefreshDataModel), Object(craft\queue\Queue))
#2 /Users/abushnell/Code/REDACTED/app/vendor/yiisoft/yii2-queue/src/Queue.php(246): putyourlightson\blitz\jobs\RefreshCacheJob->execute(Object(craft\queue\Queue))
#3 /Users/abushnell/Code/REDACTED/app/vendor/yiisoft/yii2-queue/src/cli/Queue.php(162): yii\queue\Queue->handleMessage('80754', 'O:42:"putyourli...', '300', '1')
#4 /Users/abushnell/Code/REDACTED/app/vendor/yiisoft/yii2-queue/src/cli/Command.php(146): yii\queue\cli\Queue->execute('80754', 'O:42:"putyourli...', '300', '1', '96807')
#5 [internal function]: yii\queue\cli\Command->actionExec('80754', '300', '1', '96807')
#6 /Users/abushnell/Code/REDACTED/app/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#7 /Users/abushnell/Code/REDACTED/app/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#8 /Users/abushnell/Code/REDACTED/app/vendor/yiisoft/yii2/console/Controller.php(180): yii\base\Controller->runAction('exec', Array)
#9 /Users/abushnell/Code/REDACTED/app/vendor/craftcms/cms/src/console/ControllerTrait.php(90): yii\console\Controller->runAction('exec', Array)
#10 /Users/abushnell/Code/REDACTED/app/vendor/yiisoft/yii2/base/Module.php(552): craft\queue\Command->runAction('exec', Array)
#11 /Users/abushnell/Code/REDACTED/app/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('queue/exec', Array)
#12 /Users/abushnell/Code/REDACTED/app/vendor/craftcms/cms/src/console/Application.php(90): yii\console\Application->runAction('queue/exec', Array)
#13 /Users/abushnell/Code/REDACTED/app/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('queue/exec', Array)
#14 /Users/abushnell/Code/REDACTED/app/vendor/craftcms/cms/src/console/Application.php(121): yii\console\Application->handleRequest(Object(craft\console\Request))
#15 /Users/abushnell/Code/REDACTED/app/vendor/yiisoft/yii2/base/Application.php(384): craft\console\Application->handleRequest(Object(craft\console\Request))
#16 /Users/abushnell/Code/REDACTED/app/craft(23): yii\base\Application->run()
#17 {main}
After some manual tracing I believe the error lies in this loop.
The last iteration of this that gets ran before failure is the one where the $key
is query
. Here's a screenshot of what Ray gave me when I did a dump of this info:
@aaronbushnell thanks for the details, but your Blitz version is far behind the current version 4.10.3. Can you please update to this version, refresh the cache, and retest?
Hey @bencroker, sure thing. I updated to 4.10.3 and my Craft version to 4.7.1. Unfortunately, seeing the same thing! Here's my final Ray output in that same loop before it quits:
And here's the full error I got from the queue:
2024-01-30 20:01:22 [80111] Refreshing Blitz cache (attempt: 1, pid: 4185) - Error (0.171 s)
> TypeError: Cannot assign array to property craft\elements\db\ElementQuery::$query of type ?craft\db\Query
Stack trace:
#0 /Users/abushnell/Code/REDACTED/app/vendor/putyourlightson/craft-blitz/src/helpers/RefreshCacheHelper.php(145): putyourlightson\blitz\helpers\RefreshCacheHelper::getElementQueryWithParams('craft\\elements\\...', Array)
#1 /Users/abushnell/Code/REDACTED/app/vendor/putyourlightson/craft-blitz/src/jobs/RefreshCacheJob.php(156): putyourlightson\blitz\helpers\RefreshCacheHelper::getElementQueryCacheIds(Object(putyourlightson\blitz\records\ElementQueryRecord), Object(putyourlightson\blitz\models\RefreshDataModel))
#2 /Users/abushnell/Code/REDACTED/app/vendor/putyourlightson/craft-blitz/src/jobs/RefreshCacheJob.php(74): putyourlightson\blitz\jobs\RefreshCacheJob->_populateCacheIdsFromElementQueryCaches(Object(putyourlightson\blitz\models\RefreshDataModel), Object(craft\queue\Queue))
#3 /Users/abushnell/Code/REDACTED/app/vendor/yiisoft/yii2-queue/src/Queue.php(243): putyourlightson\blitz\jobs\RefreshCacheJob->execute(Object(craft\queue\Queue))
#4 /Users/abushnell/Code/REDACTED/app/vendor/yiisoft/yii2-queue/src/cli/Queue.php(162): yii\queue\Queue->handleMessage('80111', 'O:42:"putyourli...', '300', '1')
#5 /Users/abushnell/Code/REDACTED/app/vendor/yiisoft/yii2-queue/src/cli/Command.php(146): yii\queue\cli\Queue->execute('80111', 'O:42:"putyourli...', '300', '1', '4185')
#6 [internal function]: yii\queue\cli\Command->actionExec('80111', '300', '1', '4185')
#7 /Users/abushnell/Code/REDACTED/app/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#8 /Users/abushnell/Code/REDACTED/app/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#9 /Users/abushnell/Code/REDACTED/app/vendor/yiisoft/yii2/console/Controller.php(180): yii\base\Controller->runAction('exec', Array)
#10 /Users/abushnell/Code/REDACTED/app/vendor/craftcms/cms/src/console/ControllerTrait.php(90): yii\console\Controller->runAction('exec', Array)
#11 /Users/abushnell/Code/REDACTED/app/vendor/yiisoft/yii2/base/Module.php(552): craft\queue\Command->runAction('exec', Array)
#12 /Users/abushnell/Code/REDACTED/app/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('queue/exec', Array)
#13 /Users/abushnell/Code/REDACTED/app/vendor/craftcms/cms/src/console/Application.php(91): yii\console\Application->runAction('queue/exec', Array)
#14 /Users/abushnell/Code/REDACTED/app/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('queue/exec', Array)
#15 /Users/abushnell/Code/REDACTED/app/vendor/craftcms/cms/src/console/Application.php(122): yii\console\Application->handleRequest(Object(craft\console\Request))
#16 /Users/abushnell/Code/REDACTED/app/vendor/yiisoft/yii2/base/Application.php(384): craft\console\Application->handleRequest(Object(craft\console\Request))
#17 /Users/abushnell/Code/REDACTED/app/craft(23): yii\base\Application->run()
#18 {main}
Thanks. Can you now please navigate to the Blitz Diagnostics utility and see if you can track down any entry queries that have a query
in their params? You should be able to drill into the page, then Entry
element query type.
Here’s what I see when I replicate your example.
I actually get the same error! Here's the URL I'm at:
http://REDACTED.test/admin/utilities/blitz-diagnostics/pages/element-query-type?pageId=1&elementType=craft%5Celements%5CEntry&site=en_us
Yeah, that makes sense, since the diagnostics tool runs the query to generate and render the raw SQL.
I’ve made it so that invalid params no longer throw an error. Please install this locally by running composer require "putyourlightson/craft-blitz:dev-develop as 4.11.0"
and then revisiting the diagnostics utility. You should then see Invalid params
next to any element queries that have invalid parameters.
That worked great and now the queued task no longer fails, @bencroker!
Great. That query
param (the one that contains "select"
) is curious, can you paste it here? Any idea where it might be coming from?
Absolutely! Here's the output. My guess is this is coming from the .relatedTo()
parameter on that test template because that's effectively the only query being executed in this test!
{
"sectionId":55,
"siteId":1,
"relatedTo":162,
"query":{
"select":{
"entries.sectionId":"entries.sectionId",
"entries.typeId":"entries.typeId",
"entries.authorId":"entries.authorId",
"entries.postDate":"entries.postDate",
"entries.expiryDate":"entries.expiryDate"
},
"selectOption":null,
"distinct":false,
"from":{
"subquery":{
"select":null,
"selectOption":null,
"distinct":false,
"from":null,
"groupBy":null,
"join":[
[
"INNER JOIN",
{
"entries":"{{%entries}}"
},
"[[entries.id]] = [[elements.id]]"
]
],
"having":null,
"union":null,
"withQueries":null,
"params":[
],
"queryCacheDuration":null,
"queryCacheDependency":null,
"where":{
"entries.sectionId":[
55
]
},
"limit":null,
"offset":null,
"orderBy":null,
"indexBy":null,
"emulateExecution":false
}
},
"groupBy":null,
"join":[
[
"INNER JOIN",
{
"elements":"{{%elements}}"
},
"[[elements.id]] = [[subquery.elementsId]]"
],
[
"INNER JOIN",
{
"elements_sites":"{{%elements_sites}}"
},
"[[elements_sites.id]] = [[subquery.elementsSitesId]]"
],
[
"INNER JOIN",
{
"entries":"{{%entries}}"
},
"[[entries.id]] = [[subquery.elementsId]]"
]
],
"having":null,
"union":null,
"withQueries":null,
"params":[
],
"queryCacheDuration":null,
"queryCacheDependency":null,
"where":null,
"limit":null,
"offset":null,
"orderBy":null,
"indexBy":null,
"emulateExecution":false
}
}
The strange thing is that when I put craft.entries.section('mySection').relatedTo(entry).count()
into a template and visit it, there is no query
param on the element query. You’re only doing that, no eager-loading, right?
Also, can you double check that you’ve reached this entry query via Tracked Pages
, rather than going directly through the Tracked Element Queries
?
Correct, no eager-loading! However, I do apologize, I was getting to this screen using this flow:
Tracked pages -> [page] -> Tracked element queries -> [query]
Here's a screenshot of what I was clicking on!
So, that’s strange. Why would Blitz track 3 entries and 1 asset when all you’re doing is outputting a count? Something isn’t quite adding up. Any chance you could retest with an empty template with just one single entry query?
Ahh, I see why now @bencroker. It's because, even though my template is effectively empty, SEOmatic is injecting the JSON-LD schema which contains parent pages and the Open Graph image!
Ok, so SEOmatic is executing queries you didn’t explicitly specify. Is this on the latest version of SEOmatic?
Well, I actually do expect these because this data is being generated using SEOmatic's JSON-LD schema builder. Because that contains a "breadcrumbs" attribute it's giving me the three queries for each parent page to generate that. And then the Asset is our globally-assigned image in SEOmatic's settings!
So these are expected on my end!
Mystery solved!
Really appreciate the help, Ben! 🍻
I’ve now explicitly excluded query and subquery params, in case they’ve been set, in https://github.com/putyourlightson/craft-blitz/commit/5844530d86e280b431cf08821b42124d95596d9d.
Running composer update
in your dev environment should get you that change, which should then fix the tracked entry query.
Please provide a clear and concise description of what the bug is, including: Steps to reproduce the issue.
A clear and concise description of what you expected to happen.
Screenshots of the error:
Failure screenshot from different environment/job:
The plugin and Craft version numbers.
Recently upgraded to Craft 4 from Craft 3.8.11 and noticed these issues after the upgrade, not sure if its content related or plugin related as it's been hard to continually reproduce the issue between various environments.
Here's the full stack trace from the failure:
Any guidance would be greatly appreciated!