Dronakurl / nicecrud

Edit your pydantic models with a nice GUI - CRUD Create Update Replace Delete
MIT License
14 stars 2 forks source link

Submodel example does not work on python 3.11 #1

Closed FrankDrop closed 1 month ago

FrankDrop commented 1 month ago

Using python 3.11 and running the submodel.py example, I get the following error:

Traceback (most recent call last):
  File "/workspaces/mpmca-web/frontend/submodel.py", line 23, in gui
    if context and context.get("gui"):
                   ^^^^^^^^^^^
AttributeError: 'property' object has no attribute 'get'. Did you mean: 'fget'?

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/workspaces/mpmca-web/frontend/submodel.py", line 45, in <module>
    crud_app = NiceCRUD(basemodels=[actress, another_actress], config=crud_config)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/mpmca-web/.venv/lib/python3.11/site-packages/niceguicrud/nicecrud.py", line 455, in __init__
    self.create_rows_and_cols()
  File "/workspaces/mpmca-web/.venv/lib/python3.11/site-packages/niceguicrud/nicecrud.py", line 549, in create_rows_and_cols
    rows, columns = basemodellist_to_rows_and_cols(self.basemodels)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/mpmca-web/.venv/lib/python3.11/site-packages/niceguicrud/basemodel_to_table.py", line 56, in basemodellist_to_rows_and_cols
    rows = basemodellist_to_rows(bmlist, exclude, include)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/mpmca-web/.venv/lib/python3.11/site-packages/niceguicrud/basemodel_to_table.py", line 43, in basemodellist_to_rows
    rr = bm.model_dump(include=include, exclude=exclude, context=dict(gui=True))
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/mpmca-web/.venv/lib/python3.11/site-packages/pydantic/main.py", line 364, in model_dump
    return self.__pydantic_serializer__.to_python(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.PydanticSerializationError: Error calling function `gui`: AttributeError: 'property' object has no attribute 'get'
Dronakurl commented 1 month ago

It was a typo: I used "=" and meant ":". I fixed it just now. Thanks for spotting and opening an issue