Skip to content
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

Refreshable UI with parameters throws an error #1340

Closed
alex-bezverkhniy opened this issue Aug 4, 2023 · 3 comments
Closed

Refreshable UI with parameters throws an error #1340

alex-bezverkhniy opened this issue Aug 4, 2023 · 3 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@alex-bezverkhniy
Copy link

alex-bezverkhniy commented Aug 4, 2023

Description

When I use "Refreshable UI with parameters" it throws next error:

refreshable.refresh() takes 1 positional argument but 2 were given
Traceback (most recent call last):
  File "/home/alex/Workspace/python/menu/.venv/lib/python3.10/site-packages/nicegui/events.py", line 283, in handle_event
    result = handler() if no_arguments else handler(arguments)
  File "/home/alex/Workspace/python/nicegui-menu/test.py", line 13, in <lambda>
    ui.button('Refresh for Tokyo', on_click=lambda: clock_ui.refresh('Asia/Tokyo'))
TypeError: refreshable.refresh() takes 1 positional argument but 2 were given

I use an example from the documentation:

import pytz
from datetime import datetime
from nicegui import ui

@ui.refreshable
def clock_ui(timezone: str):
    ui.label(f'Current time in {timezone}:')
    ui.label(datetime.now(tz=pytz.timezone(timezone)).strftime('%H:%M:%S'))

clock_ui('Europe/Berlin')
ui.button('Refresh', on_click=clock_ui.refresh)
ui.button('Refresh for New York', on_click=lambda: clock_ui.refresh('America/New_York'))
ui.button('Refresh for Tokyo', on_click=lambda: clock_ui.refresh('Asia/Tokyo'))

ui.run()

nicegui version 1.2.21

For version 1.3.7 I don't see the error but it doesn't refresh the UI
I've tested it on:

  • os: Linux Ubuntu - 22.04.2 LTS
  • python: - 3.10.6
  • browser: Firefox - 115.0.2 (64-bit)
@falkoschindler
Copy link
Contributor

Thanks for reporting this issue, @alex-bezverkhniy!
We introduced parameters for the refresh only recently, so I wouldn't expect it to work with version 1.2.21. But of course it should refresh the label with the most recent version 1.3.7, which it doesn't. It could be related with #1313.

@falkoschindler falkoschindler self-assigned this Aug 4, 2023
@falkoschindler falkoschindler added the bug Something isn't working label Aug 4, 2023
@falkoschindler falkoschindler added this to the 1.3.8 milestone Aug 4, 2023
@falkoschindler
Copy link
Contributor

I found and fixed the problem: The wrapped refresh function swallowed the first positional argument with the instance parameter:

def refresh(instance=self.instance, *args: Any, **kwargs: Any) -> None:

The fix is rather simple:

def refresh(*args: Any, _instance=self.instance, **kwargs: Any) -> None:

I also extended the corresponding test to cover more cases.

@alex-bezverkhniy
Copy link
Author

Thank you @falkoschindler!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants