Open GMezWheel opened 3 days ago
Hi @GMezWheel,
The "error" prop is set right in the initializer and never removed. So I don't immediately see a way this KeyError can occur. Are you using the most recent version 2.2 of NiceGUI? And can you, by any chance, provide a minimal reproducible example so we can investigate further? Thanks!
No, I'm using the previous version of nicegui : 2.1.0.dev0
I'll upgrade to version 2.2 and let you know if the problem recurs.
Thanks for your quick help.
I ran into this yesterday for the first time, on 2.2.0. Not sure what element OP is using, but mine is a select element.
When it has value=""
or value=1
, for example, instead of value=None
or a valid options label (e.g., 'Apple'), it's failing in the ValidationElement.__init__
(probably in the super call to ValueElement
). This causes the error prop to never be set.
Here's an example showing all three with a select element. I didn't try with any other input.
import traceback
from nicegui import ui
# fails
try:
ui.select(
label="Choose a fruit",
options=["Apple", "Banana", "Cherry", "Date"],
value=""
)
except Exception as e:
print("======================================")
print("Empty string error:")
traceback.print_exc()
# fails
try:
ui.select(
label="Choose a fruit",
options=["Apple", "Banana", "Cherry", "Date"],
value=1
)
except Exception as e:
print("======================================")
print("Integer value error:")
traceback.print_exc()
# works
ui.select(
label="Choose a fruit",
options=["Apple", "Banana", "Cherry", "Date"],
value=None
)
ui.run()
# one potential option to fix is changing validation_element.py:
# if self._error == error and self._props['error'] == new_error_prop:
# to
# if self._error == error and self._props.get('error') == new_error_prop:
Description
Hi, Sometimes I have this error :
Perhaps check that the key 'error' exists in the 'self._props' dictionary: