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

Component prop validation #3158

Closed
benedikt-bartscher opened this issue Apr 24, 2024 · 0 comments · Fixed by #3179
Closed

Component prop validation #3158

benedikt-bartscher opened this issue Apr 24, 2024 · 0 comments · Fixed by #3179
Labels
bug Something isn't working enhancement Anything you want improved

Comments

@benedikt-bartscher
Copy link
Contributor

benedikt-bartscher commented Apr 24, 2024

Describe the bug

While writing tests for get_attribute_access_type I discovered that Vars with Optional type annotation and a default value of None do not pass Component prop validation. But the values can always change to None at runtime.

To Reproduce

https://github.com/benedikt-bartscher/test-optional

from typing import Optional
import reflex as rx


class State(rx.State):
    no_default: str
    str_default: str = "bla"
    opt_no_default: Optional[str]
    opt_str_default: Optional[str] = "bla"
    opt_none_default: Optional[str] = None


def index() -> rx.Component:
    return rx.vstack(
        # works fine
        rx.input(value=State.no_default),
        # works fine
        rx.input(value=State.str_default),
        # TypeError: Invalid var passed for prop value, expected type typing.Union[str, int, bool], got value opt_no_default of type typing.Optional[str].
        # rx.input(value=State.opt_no_default),
        # works fine
        rx.input(value=State.opt_str_default),
        # TypeError: Invalid var passed for prop value, expected type typing.Union[str, int, bool], got value opt_none_default of type typing.Optional[str].
        # rx.input(value=State.opt_none_default),
    )


app = rx.App()
app.add_page(index)

Expected behavior
more consistent behavior with None/undefined defaults

Specifics (please complete the following information):

  • Python Version: 3.12.3
  • Reflex Version: main branch
  • OS: arch
  • Browser (Optional): ---
@Lendemor Lendemor added enhancement Anything you want improved bug Something isn't working labels Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement Anything you want improved
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants