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

Raise TypeError when ComputedVar.__init__ gets bad kwargs #4199

Merged
merged 1 commit into from
Oct 21, 2024

Conversation

masenf
Copy link
Collaborator

@masenf masenf commented Oct 18, 2024

It's easy to mis-spell rx.var(cached=True) instead of rx.var(cache=True), and in 0.6.3, this doesn't actual raise an error... the bad value is silently discarded and the var is NOT marked as being cached.

Now the error clearly indicates what the problem is and where it was introduced

...
  File "/Users/masenf/code/reflex-dev/repro-sqlalchemy-association-proxy/repro_sqlalchemy_association_proxy/repro_sqlalchemy_association_proxy.py", line 9, in <module>
    class State(rx.State):
  File "/Users/masenf/code/reflex-dev/repro-sqlalchemy-association-proxy/repro_sqlalchemy_association_proxy/repro_sqlalchemy_association_proxy.py", line 27, in State
    @rx.var(cached=True)
     ^^^^^^^^^^^^^^^^^^^
  File "/Users/masenf/code/reflex-dev/reflex/reflex/vars/base.py", line 1991, in wrapper
    return ComputedVar(
           ^^^^^^^^^^^^
  File "/Users/masenf/code/reflex-dev/reflex/reflex/vars/base.py", line 1571, in __init__
    raise TypeError(f"Unexpected keyword arguments: {tuple(kwargs)}")
TypeError: Unexpected keyword arguments: ('cached',)

It's easy to mis-spell `rx.var(cached=True)` instead of `rx.var(cache=True)`,
and in 0.6.3, this doesn't actual raise an error... the bad value is silently
discarded and the var is NOT marked as being cached.
@picklelo picklelo merged commit c05da48 into main Oct 21, 2024
31 checks passed
Kastier1 pushed a commit that referenced this pull request Oct 23, 2024
It's easy to mis-spell `rx.var(cached=True)` instead of `rx.var(cache=True)`,
and in 0.6.3, this doesn't actual raise an error... the bad value is silently
discarded and the var is NOT marked as being cached.
@masenf masenf deleted the masenf/catch-bad-rx-var-kwargs branch December 12, 2024 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants