reflex-dev / reflex-examples

A repository full of Reflex example apps.
479 stars 357 forks source link

asyncio_server failed for tick on pynecone==0.1.21 #50

Closed milochen0418 closed 1 year ago

milochen0418 commented 1 year ago

Python Version: 3.11 Mac OS NodeJS Version: 12.22.12

tick is work on pynecone==0.1.20 but not on pynecone==0.1.21 because backend part has some issue.

For the backend part, snakegame and clock example cannot work for pynecone==0.1.21 But if we use pynecone==0.1.21 to build frontend, it can work with the backend with pynecone==0.1.20

future: <Task finished name='Task-35' coro=<AsyncServer._handle_event_internal() done, defined at /Users/milochen/opt/anaconda3/envs/pynecone-311/lib/python3.11/site-packages/socketio/asyncio_server.py:522> exception=AssertionError("Unexpected event type, <class 'method'>.")>
Traceback (most recent call last):
  File "/Users/milochen/opt/anaconda3/envs/pynecone-311/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 "/Users/milochen/opt/anaconda3/envs/pynecone-311/lib/python3.11/site-packages/socketio/asyncio_server.py", line 569, in _trigger_event
    return await self.namespace_handlers[namespace].trigger_event(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/milochen/opt/anaconda3/envs/pynecone-311/lib/python3.11/site-packages/socketio/asyncio_namespace.py", line 37, in trigger_event
    ret = await handler(*args)
          ^^^^^^^^^^^^^^^^^^^^
  File "/Users/milochen/opt/anaconda3/envs/pynecone-311/lib/python3.11/site-packages/pynecone/app.py", line 582, in on_event
    update = await process(self.app, event, sid, headers, client_ip)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/milochen/opt/anaconda3/envs/pynecone-311/lib/python3.11/site-packages/pynecone/app.py", line 438, in process
    update = await state.process(event)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/milochen/opt/anaconda3/envs/pynecone-311/lib/python3.11/site-packages/pynecone/state.py", line 579, in process
    events = fix_events(events, event.token)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/milochen/opt/anaconda3/envs/pynecone-311/lib/python3.11/site-packages/pynecone/event.py", line 352, in fix_events
    assert isinstance(e, EventSpec), f"Unexpected event type, {type(e)}."
AssertionError: Unexpected event type, <class 'method'>.
milochen0418 commented 1 year ago

For the clock project, you should clean all and rebuild it again. So that the example can be tested well. Or the wrong cached .pyc with old code is in it.

rm -rf .web
rm -rf __pycache__ 
pc init 
pc run 
milochen0418 commented 1 year ago

In pynecone 0.1.20 async def process function use handler = getattr(substate, name) In pynecone 0.1.21 async def process function use
handler = substate.event_handlers[name] # type: ignore

some important code change. it look like 0.1.21 pynecone think the tick way is related to some Unexpected event type.

But After tracing the code, I still have no idea how to understand the part of this code substate.event_handlers[name]

Alek99 commented 1 year ago

Same error with the clock app

milochen0418 commented 1 year ago

Yes ~ same error with the clock app.

The current .pyc pycache/ is built by pynecone==0.1.20. If we need to reproduce the bug, we need clean the .web and the pycache/ in the project first and build it by pynecone==0.1.21.

If we push the byte codes (e.g. files in pycache) in the git server, We may miss the opportunity to test and rebuild completely. That's another reason why to prevent all pycache folders and all .pyc, .pyo, .pyd files from being uploaded. https://github.com/pynecone-io/pynecone/pull/718

milochen0418 commented 1 year ago

The bug have solved in new version of pynecone 0.1.24 (PyPI)