maxfordham / ipyautoui

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

🐛 `filter_pattern` in a field does not get sent to `FileChooser` #297

Closed mwcraig closed 3 months ago

mwcraig commented 3 months ago

Describe the bug

When a field with type Path is annotated with Field that include filter_pattern as part of json_schema_extra the filter_pattern is not set on the FileChooser UI.

To Reproduce This code will reproduce the issue. When you click on "Select" in the FileChooser all files are shown, not just those ending in *.pynb:

from pathlib import Path
from typing import Annotated

from ipyautoui import AutoUi
from pydantic import BaseModel, Field

class Example(BaseModel):
    some_file: Annotated[Path, Field(json_schema_extra={"filter_pattern": ["*.ipynb"]})]

ui = AutoUi(Example)

ui

Also, print(ui.di_widgets['some_file'].filter_pattern) gives None.

Expected behavior

Only folders and files that end in *.ipynb should be displayed in the FileChooser and print(ui.di_widgets['some_file'].filter_pattern) should give ["*.ipynb"]

Screenshots

The screenshot below shows what is displayed in the FileChooser when I run it. Note that non-notebook files are shown.

ipyautoui-fi…__2__-_JupyterLab

Additional context

NA

jgunstone commented 3 months ago

good spot - I think must have happened when I introduced this: https://github.com/maxfordham/ipyautoui/blob/a01a438d8bb436818bcc7f4101ff8a07f1a1be4d/src/ipyautoui/automapschema.py#L966 which drops kwargs that aren't traits for within the init argspec (I think I added it to silence traitlets warnings...) I've updated the init in my wrapper to have the same args as the orginal now to ensure that all the args are passed along... this will be sorted in the next release