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

Allow substates to redefine/overwrite vars #3820

Open
benedikt-bartscher opened this issue Aug 22, 2024 · 5 comments
Open

Allow substates to redefine/overwrite vars #3820

benedikt-bartscher opened this issue Aug 22, 2024 · 5 comments

Comments

@benedikt-bartscher
Copy link
Contributor

Quote from @masenf in #3805

The other big problem I see in state.py is that substates cannot redefine or override fields from a parent state. Maybe this restriction doesn't make sense anymore... if a substate redefines a field, then it should be a different value than the same-named field in a parent state, but that's just not how the code is written today.

@masenf
Copy link
Collaborator

masenf commented Aug 22, 2024

related to [REF-2300]

@benedikt-bartscher
Copy link
Contributor Author

@masenf wdyt about emitting an error/warning first? Overwriting vars could introduce more unexpected behavior and is not trivial to solve. We could add it as a feature later on if we need it

@masenf
Copy link
Collaborator

masenf commented Aug 26, 2024

i think it already does raise an error right?

import reflex as rx


class State(rx.State):
    foo: str = "bar"


class SubState(State):
    foo: str = "baz"


app = rx.App()
app.add_page(rx.logo, route="/")
reflex.utils.exceptions.VarNameError: State var "foo" in <class 'repro_overwrite.repro_overwrite.State'> has been shadowed by a substate var; use a different field name instead".

@benedikt-bartscher
Copy link
Contributor Author

iirc it only does for base vars, not for computed vars

@benedikt-bartscher
Copy link
Contributor Author

#3843

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants