Lens Visualization not editable after upload via API

Hi, we have the issue that lens visualizations that have been loaded to Kibana via saved objects API are not editable via the UI afterwards.

For example on this dashboard, it's the "CarryPick - Picks per Workstation" visualization:

Editing via the side-tab works fine, but if we try to "edit in lens" there's simply a blank screen:

In the chrome developer console we can see some errors being logged regarding to lens:
image
image

There is no difference whether we upload the visualization to an empty Kibana environment or if the expected data exists: In both cases we can not edit the visualization in the lens editor.

The workaround is to click "Apply and close" in the side-tab editor, after which we can edit it in the lens editor again.

We have compared the JSON that is saved in kibana after we can edit in the lens editor again with the one that we upload and there are no significant differences.

This is the JSON that we load via the API:

Summary
{
    "attributes": {
        "description": "", 
        "state": {
            "adHocDataViews": {}, 
            "datasourceStates": {
                "formBased": {
                    "layers": {
                        "387cd1d7-e86f-406a-bd1c-f1634f8fa97c": {
                            "columnOrder": [
                                "5c69b486-23d3-4571-b08c-d0e7b86b42c9", 
                                "391c4fc7-c995-4762-92d8-bfe5756eb67f", 
                                "20739c86-b314-44c9-a857-6c88cc85e3ff", 
                                "d6ff4c76-ef06-41dc-8df2-3a2933dae427", 
                                "f1d5508a-c2c6-4a2f-9c5b-f50b024ad235", 
                                "be6fce3b-742f-4e6b-99e0-a2f3c27c1cbd", 
                                "b14026b0-59e6-42a4-8c06-c686d5f4e5ba"
                            ], 
                            "columns": {
                                "20739c86-b314-44c9-a857-6c88cc85e3ff": {
                                    "customLabel": true, 
                                    "dataType": "number", 
                                    "isBucketed": false, 
                                    "label": "Picks", 
                                    "operationType": "count", 
                                    "params": {
                                        "emptyAsNull": true
                                    }, 
                                    "scale": "ratio", 
                                    "sourceField": "___records___"
                                }, 
                                "391c4fc7-c995-4762-92d8-bfe5756eb67f": {
                                    "customLabel": true, 
                                    "dataType": "string", 
                                    "isBucketed": true, 
                                    "label": "Workstation ID", 
                                    "operationType": "terms", 
                                    "params": {
                                        "exclude": [], 
                                        "excludeIsRegex": false, 
                                        "include": [], 
                                        "includeIsRegex": false, 
                                        "missingBucket": false, 
                                        "orderBy": {
                                            "columnId": "f1d5508a-c2c6-4a2f-9c5b-f50b024ad235", 
                                            "type": "column"
                                        }, 
                                        "orderDirection": "desc", 
                                        "otherBucket": false, 
                                        "parentFormat": {
                                            "id": "terms"
                                        }, 
                                        "size": 20
                                    }, 
                                    "scale": "ordinal", 
                                    "sourceField": "task.workstation.workstationId.keyword"
                                }, 
                                "5c69b486-23d3-4571-b08c-d0e7b86b42c9": {
                                    "customLabel": true, 
                                    "dataType": "date", 
                                    "isBucketed": true, 
                                    "label": "updateDate", 
                                    "operationType": "date_histogram", 
                                    "params": {
                                        "dropPartials": false, 
                                        "includeEmptyRows": false, 
                                        "interval": "h"
                                    }, 
                                    "scale": "interval", 
                                    "sourceField": "updateDate"
                                }, 
                                "b14026b0-59e6-42a4-8c06-c686d5f4e5ba": {
                                    "customLabel": true, 
                                    "dataType": "number", 
                                    "isBucketed": false, 
                                    "label": "Max Pick Time", 
                                    "operationType": "max", 
                                    "params": {
                                        "emptyAsNull": true
                                    }, 
                                    "scale": "ratio", 
                                    "sourceField": "task.lifeTimeExecuting"
                                }, 
                                "be6fce3b-742f-4e6b-99e0-a2f3c27c1cbd": {
                                    "customLabel": true, 
                                    "dataType": "number", 
                                    "isBucketed": false, 
                                    "label": "Min Pick Time", 
                                    "operationType": "min", 
                                    "params": {
                                        "emptyAsNull": true
                                    }, 
                                    "scale": "ratio", 
                                    "sourceField": "task.lifeTimeExecuting"
                                }, 
                                "d6ff4c76-ef06-41dc-8df2-3a2933dae427": {
                                    "customLabel": true, 
                                    "dataType": "number", 
                                    "isBucketed": false, 
                                    "label": "Picks/hr", 
                                    "operationType": "count", 
                                    "params": {
                                        "emptyAsNull": true
                                    }, 
                                    "scale": "ratio", 
                                    "sourceField": "___records___"
                                }, 
                                "f1d5508a-c2c6-4a2f-9c5b-f50b024ad235": {
                                    "customLabel": true, 
                                    "dataType": "number", 
                                    "isBucketed": false, 
                                    "label": "Avg Pick Time", 
                                    "operationType": "average", 
                                    "params": {
                                        "emptyAsNull": true
                                    }, 
                                    "scale": "ratio", 
                                    "sourceField": "task.lifeTimeExecuting"
                                }
                            }, 
                            "ignoreGlobalFilters": false, 
                            "incompleteColumns": {}
                        }
                    }
                }, 
                "indexpattern": {
                    "layers": {}
                }, 
                "textBased": {
                    "layers": {}
                }
            }, 
            "filters": [
                {
                    "$state": {
                        "store": "appState"
                    }, 
                    "meta": {
                        "alias": null, 
                        "disabled": false, 
                        "index": "5853c640-2dd5-11e9-8416-e5594c151510", 
                        "key": "searchType.keyword", 
                        "negate": false, 
                        "params": {
                            "query": "PickTask"
                        }, 
                        "type": "phrase"
                    }, 
                    "query": {
                        "match_phrase": {
                            "searchType.keyword": "PickTask"
                        }
                    }
                }, 
                {
                    "$state": {
                        "store": "appState"
                    }, 
                    "meta": {
                        "alias": null, 
                        "disabled": true, 
                        "index": "5853c640-2dd5-11e9-8416-e5594c151510", 
                        "key": "task.lifeTimeExecuting", 
                        "negate": false, 
                        "type": "exists"
                    }, 
                    "query": {
                        "exists": {
                            "field": "task.lifeTimeExecuting"
                        }
                    }
                }
            ], 
            "internalReferences": [], 
            "query": {
                "language": "kuery", 
                "query": ""
            }, 
            "visualization": {
                "columns": [
                    {
                        "alignment": "left", 
                        "columnId": "20739c86-b314-44c9-a857-6c88cc85e3ff"
                    }, 
                    {
                        "alignment": "left", 
                        "columnId": "d6ff4c76-ef06-41dc-8df2-3a2933dae427"
                    }, 
                    {
                        "alignment": "left", 
                        "collapseFn": "avg", 
                        "columnId": "5c69b486-23d3-4571-b08c-d0e7b86b42c9"
                    }, 
                    {
                        "alignment": "left", 
                        "columnId": "f1d5508a-c2c6-4a2f-9c5b-f50b024ad235"
                    }, 
                    {
                        "alignment": "left", 
                        "columnId": "be6fce3b-742f-4e6b-99e0-a2f3c27c1cbd"
                    }, 
                    {
                        "alignment": "left", 
                        "columnId": "b14026b0-59e6-42a4-8c06-c686d5f4e5ba"
                    }, 
                    {
                        "alignment": "left", 
                        "columnId": "391c4fc7-c995-4762-92d8-bfe5756eb67f"
                    }
                ], 
                "headerRowHeight": "single", 
                "layerId": "387cd1d7-e86f-406a-bd1c-f1634f8fa97c", 
                "layerType": "data", 
                "paging": {
                    "enabled": true, 
                    "size": 10
                }, 
                "rowHeight": "single"
            }
        }, 
        "title": "CarryPick - Picks per Workstation", 
        "visualizationType": "lnsDatatable"
    }, 
    "coreMigrationVersion": "8.8.0", 
    "created_at": "2024-06-20T10:16:38.652Z", 
    "id": "74089f70-c5c7-11ee-ab09-2d624c45ad92", 
    "managed": false, 
    "migrationVersion": {
        "lens": "8.9.0"
    }, 
    "namespaces": [
        "default"
    ], 
    "references": [
        {
            "id": "6c5cc350-de87-11e8-ade8-8b3a1760e7d9", 
            "name": "indexpattern-datasource-layer-387cd1d7-e86f-406a-bd1c-f1634f8fa97c", 
            "type": "index-pattern"
        }
    ], 
    "type": "lens", 
    "typeMigrationVersion": "8.9.0", 
    "updated_at": "2024-06-20T10:16:38.652Z", 
    "version": "WzczNywxXQ=="
}

This happens on the latest version of elasticsearch and kibana 8.14.1

Do you have any idea what's going on here?

Many thanks and best regards

Hi @tarkin67

I think the problem comes from this part of the JSON, which should not exists:

"indexpattern": { // <== used in very old versions, not "form_based", but not the problem
  "layers": {}
}, 
"textBased": { // <= this is the problem. Once removed it should work
  "layers": {}
}               

Hi @Marco_Liberati, thank you for your quick reply. I will test with your suggestions and get back to you!

The visualization is editable again, even with no data present. Thank you very much!