maxfordham / ipyautoui

create ipywidgets user input form pydantic model or jsonschema
https://maxfordham.github.io/ipyautoui/
38 stars 5 forks source link

🐛 A title is not generated in nested models if a custom description is provided #290

Closed mwcraig closed 4 months ago

mwcraig commented 4 months ago

Describe the bug

A title is not generated in nested models if a custom description is provided. A title cannot be added unless it differs from the name of the nested model.

To Reproduce Steps to reproduce the behavior:

  1. Paste this code into a jupyter notebook
from typing import Annotated
from pydantic import BaseModel, Field

from ipyautoui import AutoUi

class NestedStr(BaseModel):
    """A nested model"""
    string: str

class NestedFloat(BaseModel):
    """Nested float"""
    number: float | None

class Compound(BaseModel):
    """My compound model"""
    nest_str_1: Annotated[
        NestedStr,
        Field(description="Overridden description nest_str_1")
    ]
    nest_str_2: NestedStr = Field(description="Non-annotated overridden description nest_str_2")
    nest_str_3: NestedStr = Field(title="NestedStr", description="Overridden, and title doesn't work nest_str_3")
    nest_str_4: NestedStr = Field(title="Nested Str", description="Overridden, this title works nest_str_4")
    nest_float: NestedFloat

AutoUi(Compound)

Many of the nested objects do not have title (screenshot below).

Expected behavior

Each nested object will have a title generated from its name.

Screenshots

autoui_widge…__auto-e__-_JupyterLab

Additional context

Version for some of the relevant packages:

ipywidgets        8.1.1
jupyterlab       4.0.10
pydantic            2.5.3          
pydantic-core   2.14.6
jgunstone commented 4 months ago

hi @mwcraig ,

thanks for reporting. Was a simple fix, and I added a test with you example here: https://github.com/maxfordham/ipyautoui/pull/293/commits/f7e0a1568424c03c15a4dabd860cd7371d455e29

just published the fix: https://pypi.org/project/ipyautoui/0.7.12/

cheers

mwcraig commented 4 months ago

Excellent, thanks!