Error in custom widget's properties validation

Bokeh: 2.3.0
Python: 3.7.10

I’m trying to use my custom widget but I keep getting the following error:

A minimal working example to reproduce the issue:

from bokeh.models.widgets.markups import Markup
from import String, Dict, AnyRef
from bokeh.util.compiler import TypeScript
from import curdoc

TS_CODE = """
import {Markup, MarkupView} from "models/widgets/markup"
import * as p from "core/properties"

export class CustomDivView extends MarkupView {
  model: CustomDiv

  render(): void {
    if (this.model.render_as_text)
      this.markup_el.textContent = this.model.text
      this.markup_el.innerHTML = this.model.text

export namespace CustomDiv {
  export type Attrs = p.AttrsOf<Props>

  export type Props = Markup.Props & {
    render_as_text: p.Property<boolean>
    custom_styles: p.Property<({[key: string]: any} | null)>

export interface CustomDiv extends CustomDiv.Attrs {}

export class CustomDiv extends Markup {
  properties: CustomDiv.Props
  __view_type__: CustomDivView

  constructor(attrs?: Partial<CustomDiv.Attrs>) {

  static init_CustomDiv(): void {
    this.prototype.default_view = CustomDivView

    this.define<CustomDiv.Props>(({Boolean, Nullable, Dict, String}) => ({
      render_as_text: [ Boolean, false ],
      custom_styles: [ Nullable(Dict(String)), null ],

class CustomDiv(Markup):
    ''' Custom Div widget.
    __implementation__ = TypeScript(TS_CODE)

    custom_styles = Dict(String, AnyRef, default=None, help=""""
    Additional CSS rules.

div = CustomDiv(
    text="Hello world!",
    custom_styles={"div.bk.bk-clearfix": {"font-size": "30px"}}


I was using Bokeh v2.2.3 up until now and it worked well.

custom_styles = Dict(String, AnyRef, default=None)

Since 2.3 all types are non-nullable by default. Use this instead:

from import Nullable
custom_styles = Nullable(Dict(String, AnyRef), default=None)

You can skip default=None as it is the intrinsic default value for Nullable property type.

1 Like

@mateusz Thanks!