Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using stand alone file with state class #1147

Open
ustas4 opened this issue Dec 14, 2024 · 4 comments
Open

Error when using stand alone file with state class #1147

ustas4 opened this issue Dec 14, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@ustas4
Copy link

ustas4 commented Dec 14, 2024

Describe the bug
using separated file contains class State impossible

To Reproduce
Steps to reproduce the behavior:

  1. Create separated file my_state.py contains class State declaration
  2. _`import mesop as me

@me.stateclass
class State:
is_dialog_open: bool = False`_

  1. use separated class in your main.py

  2. _`import mesop as me

  3. from my_state import State
    ...
    @me.page(
    on_load=load,
    security_policy=me.SecurityPolicy(
    allowed_iframe_parents=["https://google.github.io"]
    ),
    path="/badge",
    )
    def app():
    s = me.state(State)
    ..._
    5.Start application asmesop main.py`

  4. See error

  5. **Mesop Developer Error: Tried to get the state instance for State, but it's not a state class.

Did you forget to decorate your state class State with @stateclass?**
A clear and concise description of what you expected to happen.

Screenshots
Image

Desktop System Info

  • OS: windows11
  • Browser chrome
  • Version 131.0.6778.140 (Official Build) (64-bit)

Additional context
Add any other context about the problem here.

@ustas4 ustas4 added the bug Something isn't working label Dec 14, 2024
@richard-to
Copy link
Collaborator

That's interesting. I'll try to repro your example. But I've done this before with no problem (although I'm using MacOS with Chrome, so could be a Windows specific thing but seems odd).

But your code looks fine to me at a glance.

Here's an example of separated state that does work for me (but granted haven't worked on this project in a while):

@ustas4
Copy link
Author

ustas4 commented Dec 14, 2024 via email

@ustas4
Copy link
Author

ustas4 commented Dec 15, 2024 via email

@richard-to
Copy link
Collaborator

Hmm, yeah. That's pretty strange. Not sure what could be causing the difference in behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants