reflex icon indicating copy to clipboard operation
reflex copied to clipboard

Returning event with arg is adding " to the string content

Open sheldonxxxx opened this issue 2 years ago β€’ 1 comments
trafficstars

Describe the bug A clear and concise description of what the bug is. I'm doing a recursive event with string arg, but the arg content was wrapped with a pair of " in the second pass.

To Reproduce Steps to reproduce the behavior:

  • Code/Link to Repo: async def a(self, name: str): print(name) xxxx return self.a(name)

Example output: minio "minio"

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

** Specifics (please complete the following information):**

  • Python Version:
  • Pynecone Version:
  • OS:
  • Browser (Optional):

Additional context Add any other context about the problem here.

sheldonxxxx avatar Apr 15 '23 08:04 sheldonxxxx

Perhaps related to #787; I didn't think returning an EventHandler was generally supported in 1.0.22-1.0.24.

Either way, the information provided in the issue is not enough to reproduce the problem.

I tried using this basic setup:

import pynecone as pc


class State(pc.State):
    async def a(self, name: str):
        print(f"a: {name}")
        return self.a(name)


app = pc.App(state=State)

@app.add_page
def index() -> pc.Component:
    return pc.box(pc.input(on_blur=State.a))

app.compile()

When I blur the input, I just get an exception:

a: foo
Task exception was never retrieved
future: <Task finished name='Task-36' coro=<AsyncServer._handle_event_internal() done, defined at /opt/homebrew/lib/python3.11/site-packages/socketio/asyncio_server.py:522> exception=ValidationError(model='EventHandler', errors=[{'loc': ('fn',), 'msg': '<coroutine object State.a at 0x110aec9e0> is not callable', 'type': 'type_error.callable', 'ctx': {'value': <coroutine object State.a at 0x110aec9e0>}}])>
Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.11/site-packages/socketio/asyncio_server.py", line 524, in _handle_event_internal
    r = await server._trigger_event(data[0], namespace, sid, *data[1:])
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/socketio/asyncio_server.py", line 569, in _trigger_event
    return await self.namespace_handlers[namespace].trigger_event(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/socketio/asyncio_namespace.py", line 37, in trigger_event
    ret = await handler(*args)
          ^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/pynecone/app.py", line 606, in on_event
    updates = await process(self.app, event, sid, headers, client_ip)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/pynecone/app.py", line 458, in process
    updates = [await state.process(event)]
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/pynecone/state.py", line 578, in process
    return await self.process_event(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/pynecone/state.py", line 614, in process_event
    events = fix_events(events, token)
             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/pynecone/event.py", line 350, in fix_events
    e = EventHandler(fn=e)
        ^^^^^^^^^^^^^^^^^^
  File "pydantic/main.py", line 342, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for EventHandler
fn
  <coroutine object State.a at 0x110aec9e0> is not callable (type=type_error.callable; value=<coroutine object State.a at 0x110aec9e0>)
/opt/homebrew/Cellar/[email protected]/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py:1907: RuntimeWarning:

coroutine 'State.a' was never awaited

If I change a to a non-async EventHandler

Then it hits an infinite recursion and blows the stack

Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.11/site-packages/pynecone/state.py", line 604, in process_event
    events = fn(**payload)
             ^^^^^^^^^^^^^
  File "/Users/masen/code/pynecone-io/repro-825/repro_825/repro_825.py", line 7, in a
    return self.a(name)
           ^^^^^^^^^^^^
  File "/Users/masen/code/pynecone-io/repro-825/repro_825/repro_825.py", line 7, in a
    return self.a(name)
           ^^^^^^^^^^^^
  File "/Users/masen/code/pynecone-io/repro-825/repro_825/repro_825.py", line 7, in a
    return self.a(name)
           ^^^^^^^^^^^^
  [Previous line repeated 972 more times]
  File "/Users/masen/code/pynecone-io/repro-825/repro_825/repro_825.py", line 6, in a
    print(f"a: {name}")
RecursionError: maximum recursion depth exceeded while calling a Python object

masenf avatar Apr 16 '23 03:04 masenf