craftcms / cms

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

Argument 1 passed to craft\services\Elements::getElementById() must be of the type int, string given #7460

Closed aperezg97 closed 11 months ago

aperezg97 commented 3 years ago

Description

We got this bug a few days ago with Craft 3.5.17 after uploading an asset from a Entry edit. This is weird because this doesn't happen when I upload it on the Assets section. We are using S3 as storage.

Argument 1 passed to craft\services\Elements::getElementById() must be of the type int, string given, called in /home/vagrant/sites/my-app/cms/vendor/craftcms/cms/src/controllers/AssetsController.php on line 320

Application Info

Info Version
PHP version 7.4.13
OS version Linux 4.15.0-124-generic
Database driver & version MySQL 5.7.32
Image driver & version Imagick 3.4.4 (ImageMagick 6.9.7-4)
Craft edition & version Craft Pro 3.5.17
Yii version 2.0.38
Twig version 2.14.1
Guzzle version 6.5.5

Stacktrace

I printed on log the value and it's getting a NULL.

[-][2][-][trace][craft\web\Application::_processActionRequest] Route requested: 'assets/upload'
[-][2][-][trace][yii\base\Controller::runAction] Route to run: assets/upload
[-][2][-][trace][yii\base\InlineAction::runWithParams] Running action: craft\controllers\AssetsController::actionUpload()
[-][2][-][info][debugging-error] [
    'elementId' => 'null',
]
[-][2][-][error][craft\controllers\AssetsController::actionUpload] An error occurred when saving an asset: Argument 1 passed to craft\services\Elements::getElementById() must be of the type int, string given, called in /home/user/sites/my-app/cms/vendor/craftcms/cms/src/controllers/AssetsController.php on line 320
[-][2][-][error][TypeError] TypeError: Argument 1 passed to craft\services\Elements::getElementById() must be of the type int, string given, called in /home/user/sites/my-app/cms/vendor/craftcms/cms/src/controllers/AssetsController.php on line 320 and defined in /home/user/sites/my-app/cms/vendor/craftcms/cms/src/services/Elements.php:456
Stack trace:
#0 /home/user/sites/my-app/cms/vendor/craftcms/cms/src/controllers/AssetsController.php(320): craft\services\Elements->getElementById()
#1 [internal function]: craft\controllers\AssetsController->actionUpload()
#2 /home/user/sites/my-app/cms/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()
#3 /home/user/sites/my-app/cms/vendor/yiisoft/yii2/base/Controller.php(180): yii\base\InlineAction->runWithParams()
#4 /home/user/sites/my-app/cms/vendor/craftcms/cms/src/web/Controller.php(190): yii\base\Controller->runAction()
#5 /home/user/sites/my-app/cms/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction()
#6 /home/user/sites/my-app/cms/vendor/craftcms/cms/src/web/Application.php(274): yii\base\Module->runAction()
#7 /home/user/sites/my-app/cms/vendor/craftcms/cms/src/web/Application.php(577): craft\web\Application->runAction()
#8 /home/user/sites/my-app/cms/vendor/craftcms/cms/src/web/Application.php(253): craft\web\Application->_processActionRequest()
#9 /home/user/sites/my-app/cms/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest()
#10 /home/user/sites/my-app/cms/web/index.php(30): yii\base\Application->run()
#11 {main}

Related

Related issues, maybe. I have tried these suggestions but it's not working.

https://github.com/craftcms/cms/issues/5530

Thanks in advance

brandonkelly commented 3 years ago

Are you able to reproduce this consistently?