-
Notifications
You must be signed in to change notification settings - Fork 997
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
fix: validate event #338
fix: validate event #338
Conversation
4aeadf9
to
452680c
Compare
pynecone/components/component.py
Outdated
@@ -158,7 +158,7 @@ def _create_event_chain( | |||
ValueError: If the value is not a valid event chain. | |||
""" | |||
# If it's already an event chain, return it. | |||
if isinstance(value, Var): | |||
if isinstance(value, EventChain): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think here the code is correct but the comment is incorrect.
Can we revert the code, but fix the comment to say:
# If it's a var, return it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe in addition, we need the EventChain
check? But we definitely need this current one. What code did you run that raised the ValueError
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EventChain check is for CustomComponent.
I run the same code from #310.
class State(pc.State):
some_var: bool
def index():
return pc.box(pc.icon(tag="AddIcon", on_click=State.some_var))
some_var is passed as a BaseVar, it is a child class of Var, so it is caught at first if statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain more about why we definitely need the current one when we create EventChain? BaseVar shouldn't be returned in my opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh I see - you're right this is causing the other bug it looks like. We need this line for the CustomComponent feature that I'm working on (it's not released yet, but it will allow you to create memoized React components for better performance).
But I think in adding that line it caused this other bug. Let me think a bit more on how to resolve this.
Basically for CustomComponent it can take in a Var, but for regular components it should not allow it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can add a line like
if isinstance(self, CustomComponent):
if isinstance(value, Var):
return value
Then it should fix this bug, but still work for the new feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Should I change the code as you suggest? or just close this pr and wait for your new feature?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just did a quick fix as you suggest. Thanks for the help.
40d634f
to
af351c9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the fix!
Resolve: #310
Validate EventChain explicitly, so other types will be caught as a ValueError