Cms: Integrity constraint violation - deprecationerrors.line cannot be null

Created on 17 Aug 2017  Â·  4Comments  Â·  Source: craftcms/cms

Description

Integrity constraint violation – yii\db\IntegrityException

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'line' cannot be null
The SQL being executed was: INSERT INTO `deprecationerrors` (`key`, `fingerprint`, `lastOccurrence`, `file`, `line`, `message`, `traces`, `dateCreated`, `dateUpdated`, `uid`) VALUES ('ElementQuery::getIterator()', '', '2017-08-17 14:55:44', '', NULL, 'Looping through element queries directly has been deprecated. Use the all() function to fetch the query results before looping over them.', '[{…

Steps to reproduce

  1. Loop through an element query w/o calling all()

Additional info

  • Craft version: 3 beta 24
  • PHP version: 7
  • Database driver & version: mysql
bug need more info

Most helpful comment

Thanks for pointing that out @timkelty. Made it so the deprecationerrors.line column can be nullable.

@virtualize The deprecation error itself is expected – you must start actually typing .all() when looping through an element query. (See #1902.)

All 4 comments

Not able to reproduce this. Can you come up with some simple test code that reproduces the issue and post it?

Weird…can't reproduce on my machine either, but can on coworkers machine…(MAMP, PHP 7.08)
Same repo, same DB.

It looks like the debug_backtrace() command on his machine isn't including line for some reason. Looks like he's not the only one: https://stackoverflow.com/questions/4581969/why-is-debug-backtrace-not-including-line-number-sometimes

Adding it to the list of reasons I hate MAMP!

The same here. Directly after upgrading to 3 beta 24. PHP 7.0.21 on OSX
Maybe this stack trace could help.

Deprecation error: Looping through element queries directly has been deprecated. Use the all() function to fetch the query results before looping over them. Called from /Users/virtualize/Sites/project/vendor/craftcms/cms/src/elements/db/ElementQuery.php:398 33 craft\elements\db\EntryQuery::getIterator() 32 iterator_to_array(craft\elements\db\EntryQuery, false) Called from /Users/virtualize/Sites/project/vendor/twig/twig/lib/Twig/Extension/Core.php:651 31 twig_join_filter(craft\elements\db\EntryQuery, " | ") Called from /Users/virtualize/Sites/project/storage/runtime/compiled_templates/5e/5efd67791f809a267b9fde4982a0330315662b1f1a4df4f9e63ab552f649ff0a.php:101 30 __TwigTemplate_4680fc49d7b1e06fb24d60f3112364500bf87abdf641740cc951eaeeda323fe0::macro_page_title(craft\elements\Entry) Called from /Users/virtualize/Sites/project/storage/runtime/compiled_templates/39/3912df4c4eefded4586008a785f31dc37dab9258c3da0127f86ceb6dd8dc53a5.php:52 29 __TwigTemplate_7c11019c4844517ecebd48152a01f9d70e333feb15495c58af0950e7eeb0e99e::doDisplay(["entry" => craft\elements\Entry, "variables" => ["entry" => craft\elements\Entry], "view" => craft\web\View, "SORT_ASC" => 4, ...], ["body" => [__TwigTemplate_9ffd0d55772dbb4d140796f4d7d9189daec00127c82a95006bcd84f47b53bb9f, "block_body"], "content" => [__TwigTemplate_6f131dcf8e0453b96f4bae0b1c5f0177d0d001f62f7d18d319d47e051255ece7, "block_content"]]) Called from /Users/virtualize/Sites/project/vendor/twig/twig/lib/Twig/Template.php:389 28 __TwigTemplate_7c11019c4844517ecebd48152a01f9d70e333feb15495c58af0950e7eeb0e99e::displayWithErrorHandling(["entry" => craft\elements\Entry, "variables" => ["entry" => craft\elements\Entry], "view" => craft\web\View, "SORT_ASC" => 4, ...], ["body" => [__TwigTemplate_9ffd0d55772dbb4d140796f4d7d9189daec00127c82a95006bcd84f47b53bb9f, "block_body"], "content" => [__TwigTemplate_6f131dcf8e0453b96f4bae0b1c5f0177d0d001f62f7d18d319d47e051255ece7, "block_content"]]) Called from /Users/virtualize/Sites/project/vendor/craftcms/cms/src/web/twig/Template.php:51 27 __TwigTemplate_7c11019c4844517ecebd48152a01f9d70e333feb15495c58af0950e7eeb0e99e::displayWithErrorHandling(["entry" => craft\elements\Entry, "variables" => ["entry" => craft\elements\Entry], "view" => craft\web\View, "SORT_ASC" => 4, ...], ["body" => [__TwigTemplate_9ffd0d55772dbb4d140796f4d7d9189daec00127c82a95006bcd84f47b53bb9f, "block_body"], "content" => [__TwigTemplate_6f131dcf8e0453b96f4bae0b1c5f0177d0d001f62f7d18d319d47e051255ece7, "block_content"]]) Called from /Users/virtualize/Sites/project/vendor/twig/twig/lib/Twig/Template.php:366 26 __TwigTemplate_7c11019c4844517ecebd48152a01f9d70e333feb15495c58af0950e7eeb0e99e::display(["entry" => craft\elements\Entry, "variables" => ["entry" => craft\elements\Entry], "view" => craft\web\View, "SORT_ASC" => 4, ...], ["body" => [__TwigTemplate_9ffd0d55772dbb4d140796f4d7d9189daec00127c82a95006bcd84f47b53bb9f, "block_body"], "content" => [__TwigTemplate_6f131dcf8e0453b96f4bae0b1c5f0177d0d001f62f7d18d319d47e051255ece7, "block_content"]]) Called from /Users/virtualize/Sites/project/vendor/craftcms/cms/src/web/twig/Template.php:32 25 __TwigTemplate_7c11019c4844517ecebd48152a01f9d70e333feb15495c58af0950e7eeb0e99e::display(["entry" => craft\elements\Entry, "variables" => ["entry" => craft\elements\Entry], "view" => craft\web\View, "SORT_ASC" => 4, ...], ["body" => [__TwigTemplate_9ffd0d55772dbb4d140796f4d7d9189daec00127c82a95006bcd84f47b53bb9f, "block_body"], "content" => [__TwigTemplate_6f131dcf8e0453b96f4bae0b1c5f0177d0d001f62f7d18d319d47e051255ece7, "block_content"]]) Called from /Users/virtualize/Sites/project/storage/runtime/compiled_templates/a3/a3fc6bef1d68da4dd1f1c6e5f606f26916e34d87eef9aef73f39b996a8cf86e1.php:25 24 __TwigTemplate_9ffd0d55772dbb4d140796f4d7d9189daec00127c82a95006bcd84f47b53bb9f::doDisplay(["entry" => craft\elements\Entry, "variables" => ["entry" => craft\elements\Entry], "view" => craft\web\View, "SORT_ASC" => 4, ...], ["body" => [__TwigTemplate_9ffd0d55772dbb4d140796f4d7d9189daec00127c82a95006bcd84f47b53bb9f, "block_body"], "content" => [__TwigTemplate_6f131dcf8e0453b96f4bae0b1c5f0177d0d001f62f7d18d319d47e051255ece7, "block_content"]]) Called from /Users/virtualize/Sites/project/vendor/twig/twig/lib/Twig/Template.php:389 23 __TwigTemplate_9ffd0d55772dbb4d140796f4d7d9189daec00127c82a95006bcd84f47b53bb9f::displayWithErrorHandling(["entry" => craft\elements\Entry, "variables" => ["entry" => craft\elements\Entry], "view" => craft\web\View, "SORT_ASC" => 4, ...], ["body" => [__TwigTemplate_9ffd0d55772dbb4d140796f4d7d9189daec00127c82a95006bcd84f47b53bb9f, "block_body"], "content" => [__TwigTemplate_6f131dcf8e0453b96f4bae0b1c5f0177d0d001f62f7d18d319d47e051255ece7, "block_content"]]) Called from /Users/virtualize/Sites/project/vendor/craftcms/cms/src/web/twig/Template.php:51 22 __TwigTemplate_9ffd0d55772dbb4d140796f4d7d9189daec00127c82a95006bcd84f47b53bb9f::displayWithErrorHandling(["entry" => craft\elements\Entry, "variables" => ["entry" => craft\elements\Entry], "view" => craft\web\View, "SORT_ASC" => 4, ...], ["body" => [__TwigTemplate_9ffd0d55772dbb4d140796f4d7d9189daec00127c82a95006bcd84f47b53bb9f, "block_body"], "content" => [__TwigTemplate_6f131dcf8e0453b96f4bae0b1c5f0177d0d001f62f7d18d319d47e051255ece7, "block_content"]]) Called from /Users/virtualize/Sites/project/vendor/twig/twig/lib/Twig/Template.php:366 21 __TwigTemplate_9ffd0d55772dbb4d140796f4d7d9189daec00127c82a95006bcd84f47b53bb9f::display(["entry" => craft\elements\Entry, "variables" => ["entry" => craft\elements\Entry], "view" => craft\web\View, "SORT_ASC" => 4, ...], ["content" => [__TwigTemplate_6f131dcf8e0453b96f4bae0b1c5f0177d0d001f62f7d18d319d47e051255ece7, "block_content"]]) Called from /Users/virtualize/Sites/project/vendor/craftcms/cms/src/web/twig/Template.php:32 20 __TwigTemplate_9ffd0d55772dbb4d140796f4d7d9189daec00127c82a95006bcd84f47b53bb9f::display(["entry" => craft\elements\Entry, "variables" => ["entry" => craft\elements\Entry], "view" => craft\web\View, "SORT_ASC" => 4, ...], ["content" => [__TwigTemplate_6f131dcf8e0453b96f4bae0b1c5f0177d0d001f62f7d18d319d47e051255ece7, "block_content"]]) Called from /Users/virtualize/Sites/project/storage/runtime/compiled_templates/7a/7afbb6640e9994b82e9a2e90657e7b7c8d85a0baeac3895882c3976ab9a91820.php:24 19 __TwigTemplate_6f131dcf8e0453b96f4bae0b1c5f0177d0d001f62f7d18d319d47e051255ece7::doDisplay(["entry" => craft\elements\Entry, "variables" => ["entry" => craft\elements\Entry], "view" => craft\web\View, "SORT_ASC" => 4, ...], ["content" => [__TwigTemplate_6f131dcf8e0453b96f4bae0b1c5f0177d0d001f62f7d18d319d47e051255ece7, "block_content"]]) Called from /Users/virtualize/Sites/project/vendor/twig/twig/lib/Twig/Template.php:389 18 __TwigTemplate_6f131dcf8e0453b96f4bae0b1c5f0177d0d001f62f7d18d319d47e051255ece7::displayWithErrorHandling(["entry" => craft\elements\Entry, "variables" => ["entry" => craft\elements\Entry], "view" => craft\web\View, "SORT_ASC" => 4, ...], ["content" => [__TwigTemplate_6f131dcf8e0453b96f4bae0b1c5f0177d0d001f62f7d18d319d47e051255ece7, "block_content"]]) Called from /Users/virtualize/Sites/project/vendor/craftcms/cms/src/web/twig/Template.php:51 17 __TwigTemplate_6f131dcf8e0453b96f4bae0b1c5f0177d0d001f62f7d18d319d47e051255ece7::displayWithErrorHandling(["entry" => craft\elements\Entry, "variables" => ["entry" => craft\elements\Entry], "view" => craft\web\View, "SORT_ASC" => 4, ...], ["content" => [__TwigTemplate_6f131dcf8e0453b96f4bae0b1c5f0177d0d001f62f7d18d319d47e051255ece7, "block_content"]]) Called from /Users/virtualize/Sites/project/vendor/twig/twig/lib/Twig/Template.php:366 16 __TwigTemplate_6f131dcf8e0453b96f4bae0b1c5f0177d0d001f62f7d18d319d47e051255ece7::display(["entry" => craft\elements\Entry, "variables" => ["entry" => craft\elements\Entry]], []) Called from /Users/virtualize/Sites/project/vendor/craftcms/cms/src/web/twig/Template.php:32 15 __TwigTemplate_6f131dcf8e0453b96f4bae0b1c5f0177d0d001f62f7d18d319d47e051255ece7::display(["entry" => craft\elements\Entry, "variables" => ["entry" => craft\elements\Entry]]) Called from /Users/virtualize/Sites/project/vendor/twig/twig/lib/Twig/Template.php:374 14 __TwigTemplate_6f131dcf8e0453b96f4bae0b1c5f0177d0d001f62f7d18d319d47e051255ece7::render(["entry" => craft\elements\Entry, "variables" => ["entry" => craft\elements\Entry]]) Called from /Users/virtualize/Sites/project/vendor/twig/twig/lib/Twig/Environment.php:288 13 craft\web\twig\Environment::render("singles/homepage", ["entry" => craft\elements\Entry, "variables" => ["entry" => craft\elements\Entry]]) Called from /Users/virtualize/Sites/project/vendor/craftcms/cms/src/web/View.php:254 12 craft\web\View::renderTemplate("singles/homepage", ["entry" => craft\elements\Entry, "variables" => ["entry" => craft\elements\Entry]]) Called from /Users/virtualize/Sites/project/vendor/craftcms/cms/src/web/View.php:302 11 craft\web\View::renderPageTemplate("singles/homepage", ["entry" => craft\elements\Entry, "variables" => ["entry" => craft\elements\Entry]]) Called from /Users/virtualize/Sites/project/vendor/craftcms/cms/src/web/Controller.php:101 10 craft\controllers\TemplatesController::renderTemplate("singles/homepage", ["entry" => craft\elements\Entry, "variables" => ["entry" => craft\elements\Entry]]) Called from /Users/virtualize/Sites/project/vendor/craftcms/cms/src/controllers/TemplatesController.php:79 9 craft\controllers\TemplatesController::actionRender("singles/homepage", ["entry" => craft\elements\Entry, "variables" => ["entry" => craft\elements\Entry]]) 8 call_user_func_array([craft\controllers\TemplatesController, "actionRender"], ["singles/homepage", ["entry" => craft\elements\Entry]]) Called from /Users/virtualize/Sites/project/vendor/yiisoft/yii2/base/InlineAction.php:57 7 yii\base\InlineAction::runWithParams(["template" => "singles/homepage", "variables" => ["entry" => craft\elements\Entry]]) Called from /Users/virtualize/Sites/project/vendor/yiisoft/yii2/base/Controller.php:156 6 craft\controllers\TemplatesController::runAction("render", ["template" => "singles/homepage", "variables" => ["entry" => craft\elements\Entry]]) Called from /Users/virtualize/Sites/project/vendor/yiisoft/yii2/base/Module.php:523 5 craft\web\Application::runAction("templates/render", ["template" => "singles/homepage", "variables" => ["entry" => craft\elements\Entry]]) Called from /Users/virtualize/Sites/project/vendor/craftcms/cms/src/web/Application.php:241 4 craft\web\Application::runAction("templates/render", ["template" => "singles/homepage", "variables" => ["entry" => craft\elements\Entry]]) Called from /Users/virtualize/Sites/project/vendor/yiisoft/yii2/web/Application.php:102 3 craft\web\Application::handleRequest(craft\web\Request) Called from /Users/virtualize/Sites/project/vendor/craftcms/cms/src/web/Application.php:206 2 craft\web\Application::handleRequest(craft\web\Request) Called from /Users/virtualize/Sites/project/vendor/yiisoft/yii2/base/Application.php:380 1 craft\web\Application::run() Called from /Users/virtualize/Sites/project/web/index.php:21

Thanks for pointing that out @timkelty. Made it so the deprecationerrors.line column can be nullable.

@virtualize The deprecation error itself is expected – you must start actually typing .all() when looping through an element query. (See #1902.)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mccombs picture mccombs  Â·  3Comments

leigeber picture leigeber  Â·  3Comments

angrybrad picture angrybrad  Â·  3Comments

angrybrad picture angrybrad  Â·  3Comments

mattstein picture mattstein  Â·  3Comments