Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GenerateDataModel::addElementId(): Argument #1 ($elementId) must be of type int, null given #594

Closed
KarlBishop opened this issue Dec 13, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@KarlBishop
Copy link

I'm updating a project to Craft 4 and have hit this error related to Blitz cache.

One particular page on the site is returning a 500 Internal Server Error and falling back to the error template.

In web.log I can see a TypeError was thrown by Blitz:

info 1702434930 [-][-][-][error][TypeError] putyourlightson\blitz\models\GenerateDataModel::addElementId(): Argument #1 ($elementId) must be of type int, null given, called in /var/www/html/vendor/putyourlightson/craft-blitz/src/models/GenerateDataModel.php on line 106 at /var/www/html/vendor/putyourlightson/craft-blitz/src/models/GenerateDataModel.php:92 
info 1702434930 [-][-][-][warning][application] Request context: 
info     $_GET = [] 
info      
info     $_POST = [] 
info      
info     $_FILES = [] 
info      
info     $_COOKIE = [ 
info         '..._username' => '...' 
info         '_gcl_au' => '...' 
info         '_fbp' => '...' 
info         'CRAFT_CSRF_TOKEN' => '...' 
info         'CraftSessionId' => '...' 
info         '..._identity' => '...' 
info         'SERVD_LOGGED_IN_STATUS' => '1' 
info     ] 
info      
info     $_SESSION = [ 
info         '...__flash' => [] 
info         '...__token' => '...' 
info         '...__id' => 1 
info         '__authKey' => '...' 
info         '...__expire' => 1703644529 
info         '__duration' => 1209600 
info         'twofactorauth_verified' => 1702434710 
info     ] 
info Stack trace: 
info #0 /var/www/html/vendor/putyourlightson/craft-blitz/src/models/GenerateDataModel.php:106 
info #1 /var/www/html/vendor/putyourlightson/craft-blitz/src/services/GenerateCacheService.php:210 
info #2 /var/www/html/vendor/putyourlightson/craft-blitz/src/services/GenerateCacheService.php:128 
info #3 /var/www/html/vendor/yiisoft/yii2/base/Event.php:312 
info #4 /var/www/html/vendor/yiisoft/yii2/base/Component.php:642 
info #5 /var/www/html/vendor/craftcms/cms/src/elements/db/ElementQuery.php:1986 
info #6 /var/www/html/vendor/craftcms/cms/src/elements/db/ElementQuery.php:3082 
info #7 /var/www/html/vendor/craftcms/cms/src/elements/db/ElementQuery.php:1542 
info #8 /var/www/html/vendor/yiisoft/yii2/db/Query.php:251 
info #9 /var/www/html/vendor/craftcms/cms/src/db/Query.php:247 
info #10 /var/www/html/vendor/craftcms/cms/src/elements/db/ElementQuery.php:1581 
info #11 /var/www/html/vendor/twig/twig/src/Extension/CoreExtension.php:1607 
info #12 /var/www/html/vendor/craftcms/cms/src/helpers/Template.php:129 
info #13 /var/www/html/storage/runtime/compiled_templates/96/96d179221a63c83b3dd530129b090f59.php:48 
info #14 /var/www/html/vendor/twig/twig/src/Template.php:394 
info #15 /var/www/html/vendor/twig/twig/src/Template.php:367 
info #16 /var/www/html/vendor/twig/twig/src/Template.php:379 
info #17 /var/www/html/vendor/twig/twig/src/TemplateWrapper.php:40 
info #18 /var/www/html/vendor/twig/twig/src/Environment.php:277 
info #19 /var/www/html/vendor/craftcms/cms/src/web/View.php:482 
info #20 /var/www/html/vendor/craftcms/cms/src/web/View.php:535 
info #21 /var/www/html/vendor/craftcms/cms/src/web/TemplateResponseFormatter.php:57 
info #22 /var/www/html/vendor/yiisoft/yii2/web/Response.php:1100 
info #23 /var/www/html/vendor/craftcms/cms/src/web/Response.php:337 
info #24 /var/www/html/vendor/yiisoft/yii2/web/Response.php:340 
info #25 /var/www/html/vendor/yiisoft/yii2/base/Application.php:390 
info #26 /var/www/html/web/index.php:12 

The site is hosted on Servd and we followed their guide to integrate Blitz Cache with the Servd Static Cache:
https://servd.host/docs/caching-with-blitz

We're currently on:
Craft CMS 4.5.11.1
Blitz 4.9.3

Any ideas what could cause this?

@KarlBishop KarlBishop added the bug Something isn't working label Dec 13, 2023
@KarlBishop KarlBishop changed the title GenerateDataModel::addElementId(): Argument #1 ($elementId) must be of type int, null givenArgument GenerateDataModel::addElementId(): Argument #1 ($elementId) must be of type int, null given Dec 13, 2023
@bencroker
Copy link
Collaborator

bencroker commented Dec 13, 2023

Thanks for reporting this. I’m not sure why an element ID might be null, but I’ve added prevention against this in cf4b300 for the next release.

@bencroker
Copy link
Collaborator

Released in 4.9.4.

@KarlBishop
Copy link
Author

Brilliant, that fixed our issue - thanks @bencroker! Have a great end of the year 🎉

@thomas-jaeger
Copy link

The element id might be null, if elements are fetched without id (like Entry::find()->section('xxx')->select(['name'])). We had the same issue. Thanks @bencroker for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants