Skip to content

ipywidgets expects Comm, not BaseComm #1090

@matthewturk

Description

Hi! I've been trying to track down an issue with my usage of ipywidgets, described on discourse. The basic gist is:

  • I'm attempting to create a widget from the client by using a model.widget_manager's method new_widget. In previous versions, this worked, but now, it doesn't.
  • The issue seems to stem from the kernel attempting to create a new comm instance for a widget, but supplying to that widget a BaseComm rather than a Comm, which throws a validation error.

After digging through this, it looks to me like ipywidgets declares comm = Instance('ipykernel.comm.Comm', allow_none=True), but ipykernel.ipkernel.create_comm explicitly creates a BaseComm, so the traitlet doesn't validate, and the comm fails to properly initialize. This results in the widgets not being synced back to the kernel from the frontend.

I confess that while I've spent time going through the code, I'm not entirely sure if this could potentially be a version mismatch, or if this is an oversight for a use case that may not come up terribly frequently.

My versions:

  • ipywidgets - 8.0.4
  • ipykernel - 6.21.1
  • comm - 0.1.2

I was able to address the problem I was having by changing the import and usage of BaseComm to Comm in ipkernel.py, and so if this is an acceptable solution I'd be happy to issue a pull request. (My hesitance is that there may be unexpected downstream effects of a change to something so deep in the kernel code, and so I wanted to open the issue as possible first step.)

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions