From e32ffb6aed87e2bf8b1bb1ce3ccb11702e6467ef Mon Sep 17 00:00:00 2001 From: Nikhil Rao Date: Fri, 23 Dec 2022 11:18:19 -0800 Subject: [PATCH] Fix event handler formatting (#174) --- pynecone/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pynecone/utils.py b/pynecone/utils.py index a86af086a..6e83aefbf 100644 --- a/pynecone/utils.py +++ b/pynecone/utils.py @@ -836,7 +836,12 @@ def format_event_handler(handler: EventHandler) -> str: state_name, name = parts[-2:] # Construct the full event handler name. - state = vars(sys.modules[handler.fn.__module__])[state_name] + try: + # Try to get the state from the module. + state = vars(sys.modules[handler.fn.__module__])[state_name] + except: + # If the state isn't in the module, just return the function name. + return handler.fn.__qualname__ return ".".join([state.get_full_name(), name])