verbb / smith

A Craft CMS plugin to add copy, paste and clone functionality to Matrix blocks.
MIT License
25 stars 9 forks source link

Cloning a matrix block in a provisional draft causes a server error #23

Closed MoritzLost closed 2 years ago

MoritzLost commented 2 years ago

Description

Trying to clone a matrix block immediately after creating a new entry causes a server error. Here's a screencast showing the error:

https://user-images.githubusercontent.com/10146880/171408417-a9b1968d-fc49-4500-8b0e-9dad6662ee05.mov

I checked the network tab, the request comes back as a HTTP 500 error. Here's the included strack trace:

{
    "error": "Invalid numeric value: new1",
    "exception": "yii\\base\\InvalidArgumentException",
    "file": "/Users/moritz/Desktop/projects/craftbase/vendor/craftcms/cms/src/helpers/Db.php",
    "line": 566,
    "trace": [
        {
            "file": "/Users/moritz/Desktop/projects/craftbase/vendor/craftcms/cms/src/helpers/Db.php",
            "line": 813,
            "function": "parseParam",
            "class": "craft\\helpers\\Db",
            "type": "::"
        },
        {
            "file": "/Users/moritz/Desktop/projects/craftbase/vendor/craftcms/cms/src/elements/db/MatrixBlockQuery.php",
            "line": 600,
            "function": "parseNumericParam",
            "class": "craft\\helpers\\Db",
            "type": "::"
        },
        {
            "file": "/Users/moritz/Desktop/projects/craftbase/vendor/craftcms/cms/src/elements/db/MatrixBlockQuery.php",
            "line": 504,
            "function": "_normalizeFieldId",
            "class": "craft\\elements\\db\\MatrixBlockQuery",
            "type": "->"
        },
        {
            "file": "/Users/moritz/Desktop/projects/craftbase/vendor/craftcms/cms/src/elements/db/ElementQuery.php",
            "line": 1258,
            "function": "beforePrepare",
            "class": "craft\\elements\\db\\MatrixBlockQuery",
            "type": "->"
        },
        {
            "file": "/Users/moritz/Desktop/projects/craftbase/vendor/yiisoft/yii2/db/QueryBuilder.php",
            "line": 227,
            "function": "prepare",
            "class": "craft\\elements\\db\\ElementQuery",
            "type": "->"
        },
        {
            "file": "/Users/moritz/Desktop/projects/craftbase/vendor/yiisoft/yii2/db/Query.php",
            "line": 157,
            "function": "build",
            "class": "yii\\db\\QueryBuilder",
            "type": "->"
        },
        {
            "file": "/Users/moritz/Desktop/projects/craftbase/vendor/yiisoft/yii2/db/Query.php",
            "line": 287,
            "function": "createCommand",
            "class": "yii\\db\\Query",
            "type": "->"
        },
        {
            "file": "/Users/moritz/Desktop/projects/craftbase/vendor/craftcms/cms/src/db/Query.php",
            "line": 180,
            "function": "one",
            "class": "yii\\db\\Query",
            "type": "->"
        },
        {
            "file": "/Users/moritz/Desktop/projects/craftbase/vendor/craftcms/cms/src/elements/db/ElementQuery.php",
            "line": 1450,
            "function": "one",
            "class": "craft\\db\\Query",
            "type": "->"
        },
        {
            "file": "/Users/moritz/Desktop/projects/craftbase/vendor/verbb/smith/src/controllers/FieldController.php",
            "line": 52,
            "function": "one",
            "class": "craft\\elements\\db\\ElementQuery",
            "type": "->"
        },
        {
            "function": "actionRenderMatrixBlocks",
            "class": "verbb\\smith\\controllers\\FieldController",
            "type": "->"
        },
        {
            "file": "/Users/moritz/Desktop/projects/craftbase/vendor/yiisoft/yii2/base/InlineAction.php",
            "line": 57,
            "function": "call_user_func_array"
        },
        {
            "file": "/Users/moritz/Desktop/projects/craftbase/vendor/yiisoft/yii2/base/Controller.php",
            "line": 178,
            "function": "runWithParams",
            "class": "yii\\base\\InlineAction",
            "type": "->"
        },
        {
            "file": "/Users/moritz/Desktop/projects/craftbase/vendor/yiisoft/yii2/base/Module.php",
            "line": 552,
            "function": "runAction",
            "class": "yii\\base\\Controller",
            "type": "->"
        },
        {
            "file": "/Users/moritz/Desktop/projects/craftbase/vendor/craftcms/cms/src/web/Application.php",
            "line": 301,
            "function": "runAction",
            "class": "yii\\base\\Module",
            "type": "->"
        },
        {
            "file": "/Users/moritz/Desktop/projects/craftbase/vendor/craftcms/cms/src/web/Application.php",
            "line": 625,
            "function": "runAction",
            "class": "craft\\web\\Application",
            "type": "->"
        },
        {
            "file": "/Users/moritz/Desktop/projects/craftbase/vendor/craftcms/cms/src/web/Application.php",
            "line": 280,
            "function": "_processActionRequest",
            "class": "craft\\web\\Application",
            "type": "->"
        },
        {
            "file": "/Users/moritz/Desktop/projects/craftbase/vendor/yiisoft/yii2/base/Application.php",
            "line": 384,
            "function": "handleRequest",
            "class": "craft\\web\\Application",
            "type": "->"
        },
        {
            "file": "/Users/moritz/Desktop/projects/craftbase/web/index.php",
            "line": 11,
            "function": "run",
            "class": "yii\\base\\Application",
            "type": "->"
        },
        {
            "file": "/Users/moritz/.composer/vendor/laravel/valet/server.php",
            "line": 234,
            "function": "require"
        }
    ]
}

Copying works fine (at least it doesn't produce an error), but pasting in this scenario causes an error as well. The exception and stack trace are identical in this case.

EDIT: After some further testing, it's unrelated to whether the entry has been saved before. The error occurs when trying to save a matrix block that was just created and hasn't been saved yet. Creating a new block normally and then trying to clone it causes the same error as seen above, even on published entries.

Steps to reproduce

  1. Create a new entry with a matrix field and create a new block in that field.
  2. Try to clone the block.

Additional info

engram-design commented 2 years ago

Should be fixed in 2.0.0