Skip to content

jupyter websocket messages not updating UI #369

@dlcrista

Description

@dlcrista

I'm wondering how does the frontend know what cellId each cell is? If I make a call to /api/contents/myfile.ipynb?content=1 , no cellId appears on the returned file contents model.

When I inspect the wss message that is sent from the frontend upon clicking the execute button in the UI (through the dev tools), I can see that the structure of the message is as follows:

{
    "header": {
        "username": "",
        "version": "5.2",
        "msg_type": "execute_request",
        "session": "some uuid1",
        "msg_id": "some uuid2"
    },
    "metadata": {
        "cellId": "some uuid3",
        "deletedCells": []
    },    
    "parent_header": {},
    "channel": "shell",
    "content": {
        "silent": false,
        "store_history": true,
        "user_expressions": {},
        "allow_stdin": true,
        "stop_on_error": true,
        "code": "print(\"doge\")"
    },
    "buffers": []
}

When I refresh the page, the cellId for the same cell is always different. How is it tied to the UI's cells?

I know that the session id is received upon making a get request to /api/kernels/{kernel_id}/channels and from the docs, msg_id seems to be randomly created from str(uuid.uuid4()) but how do cells become tied to particular ids? The only way I can get my code to appear under a cell in the UI is if I reuse the same msg_id that the frontend created upon clicking the run button on the UI (and if I do that, then session and cellId can be empty since I guess it's inferred from the msg_id)

Not sure if this is the right place to ask this question, if not, please point me in the correct direction.
Thanks


Edit: From snooping around the UI, it looks like the model has a cellId. I have not verified manually trying to get the cellId through python or javascript

(function (CodeCell) {
    /**
     * Execute a cell given a client session.
     */
    function execute(cell, session, metadata) {
        let model = cell.model;
        let code = model.value.text;
        if (!code.trim() || !session.kernel) {
            model.executionCount = null;
            model.outputs.clear();
            return Promise.resolve(void 0);
        }
        let cellId = { cellId: model.id };
        metadata = Object.assign({}, metadata, cellId);
        model.executionCount = null;
        cell.outputHidden = false;
        cell.setPrompt('*');
        model.trusted = true;
        return outputarea_1.OutputArea.execute(code, cell.outputArea, session, metadata)
            .then(msg => {
            model.executionCount = msg.content.execution_count;
            return msg;
        })
            .catch(e => {
            if (e.message === 'Canceled') {
                cell.setPrompt('');
            }
            throw e;
        });
    }
    CodeCell.execute = execute;
})(CodeCell = exports.CodeCell || (exports.CodeCell = {}));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions