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

Variable-Name/String Collision Causes Unintended Variable Replacement #4369

Closed
DeepQuantum opened this issue Nov 12, 2024 · 2 comments · Fixed by #4371
Closed

Variable-Name/String Collision Causes Unintended Variable Replacement #4369

DeepQuantum opened this issue Nov 12, 2024 · 2 comments · Fixed by #4371
Assignees
Labels
bug Something isn't working

Comments

@DeepQuantum
Copy link

When you have a state var variable foo, and another state var bar which has the string value foo, the value of bar might sometimes become the value of foo.

  • Python Version: 3.12
  • Reflex Version: 0.6.4
  • OS: Windows 11

Example:

# State.py

class TableState(rx.State):

    password = "secret123"

    ...
    
    search: str = ""

    ...
    
    def apply_search(self, search: str) -> None:
        self.search = search
        if search == "":
            return
        ...

# Components.py
    
Search = rx.input(
    rx.button(
        rx.icon("x", size=12),
        ...
        on_click=lambda: TableState.apply_search(""),
    ),
    ...
    value=TableState.search,
    on_change=TableState.apply_search,
)

So if i now type password into my search bar, the contents of the search bar become the contents of the password variable. I don't know if I'm missing something super obvious here, but this seems a little suspicious to me. It's also not that I'm passing the contents of the variable into apply_search somewhere, when I log the input, it's always just the actual text that I write in.

Screen.Recording.2024-11-12.143353.mp4
@DeepQuantum DeepQuantum added the bug Something isn't working label Nov 12, 2024
Copy link

linear bot commented Nov 12, 2024

@masenf
Copy link
Collaborator

masenf commented Nov 12, 2024

Thanks for reporting. The bug appears to be in State.get_delta, specifically how it calls State.get_value.

@masenf masenf self-assigned this Nov 12, 2024
masenf added a commit that referenced this issue Nov 12, 2024
Because of some dodgy logic in Base.get_value and State.dict / State.get_delta
when the value of some state var X happened to be the name of another var in
the state Y, then the value for X would be returned as the value of Y.

wat.

Fixes #4369
@masenf masenf closed this as completed in 5d88263 Nov 12, 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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants