Skip to content

FastAPI crashes without trace with a substate of a substate #140

@matt-grain

Description

@matt-grain

I finally understood what causes the problem (but not why). due to the refactoring, I have sub-sub-states and that is the issue:

from typing import List, Dict
import pynecone as pc


class ButtonModel(pc.Model, table=False):

    title: str


class AppState(pc.State):
    """The app state."""

    default_field: str


class LocalState(AppState):

    button_state: List[bool] = [False for i in range(10)]

    @pc.var
    def get_buttonmodel(self) -> List[ButtonModel]:
        self.default_field = "break me"
        return [ButtonModel(id=0, title="this is a button which breaks pynecone"), ButtonModel(id=1, title=self.default_field)]


class SubState(LocalState):
    def trigger_fault(self) -> None:
        print("error")


def index():
    return pc.center(
        pc.vstack(
            pc.foreach(LocalState.get_buttonmodel, lambda a_model: display_form(a_model)),
            spacing="1.5em",
            font_size="2em",
        ),
        padding_top="10%",
    )


def display_form(model: ButtonModel):

    return pc.button(model.title, size="lg", on_click=SubState.trigger_fault)


# Add state and page to the app.
app = pc.App(state=AppState)
app.add_page(index)
app.compile()

image

Originally posted by @matt-grain in #136 (comment)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions