justpy icon indicating copy to clipboard operation
justpy copied to clipboard

Task exception was never retrieved future with KeyError

Open giodegas opened this issue 4 years ago • 3 comments

On my bak-end JustPy app I see quite some times this kind of errors:

[10004] 2021-07-11 04:47:25 ERROR    Task exception was never retrieved future: <Task finished name='Task-29878' coro=<handle_event() done, defined at /usr/local/lib/python3.8/site-packages/justpy/justpy.py:301> exception=KeyError(2644)>
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/justpy/justpy.py", line 322, in handle_event
    c = JustpyBaseComponent.instances[event_data['id']]
KeyError: 2644

I would appreciate which cause is triggering it, in order to prevent to happen.

giodegas avatar Jul 12 '21 09:07 giodegas

I would be happy to take a look at this issue if you can create a small program that replicates it.

elimintz avatar Jul 14 '21 14:07 elimintz

Not sure whether the same applies to @giodegas, but this is an error you get when an event handler tries to update a component that has been deleted in the meantime (e.g. in another preceding event).

See below example (modified from the tutorial). If you click e.g. button 1 and then within 3 seconds you click button 2, you'll get a KeyError message. Don't think this is a bug, though might be an idea to handle the error more gracefully and show a more descriptive message?

import justpy as jp
import time

def button_click(self, msg):
    self.num_clicked += 1
    self.message.text = f'{self.text} clicked. Number of clicks: {self.num_clicked}'
    self.set_class('bg-red-500')
    self.set_class('bg-red-700', 'hover')
    self.button_div.delete_components()
    time.sleep(3)

def index():
    number_of_buttons = 25
    wp = jp.WebPage()
    button_div = jp.Div(classes='flex m-4 flex-wrap', a=wp)
    button_classes = 'w-32 mr-2 mb-2 bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-full'
    message = jp.Div(text='No button clicked yet', classes='text-2xl border m-4 p-2', a=wp)
    for i in range(1, number_of_buttons + 1):
        b = jp.Button(text=f'Button {i}', a=button_div, classes=button_classes, click=button_click, button_div=button_div)
        b.message = message
        b.num_clicked = 0
    return wp 

jp.justpy(index, port=5000)

platinops avatar Aug 30 '21 14:08 platinops

I'll take a look. It is not clear to me how to be more descriptive except perhaps suggest that the element does not exist anymore.

I set the CRASH option to True while developing so the application halts when such errors occur.

elimintz avatar Aug 30 '21 16:08 elimintz

There is now a selenium test case for this scenario.

Starting test testIssue279, debug=False ...
ERROR base_events: Task exception was never retrieved
future: <Task finished coro=<handle_event() done, defined at /home/runner/work/justpy/justpy/justpy/justpy.py:391> exception=KeyError(2)>
Traceback (most recent call last):
  File "/home/runner/work/justpy/justpy/justpy/justpy.py", line 416, in handle_event
    c = JustpyBaseComponent.instances[event_data["id"]]
KeyError: 2

WolfgangFahl avatar Sep 06 '22 16:09 WolfgangFahl

@giodegas would you please provide a comment only one line pull request so that you show up in the list of collaborators ...

WolfgangFahl avatar Sep 06 '22 17:09 WolfgangFahl

Test occassionaly times out in CI

WolfgangFahl avatar Sep 20 '23 09:09 WolfgangFahl

thank you for your time on this issue!

giodegas avatar Jan 04 '24 12:01 giodegas