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

ValidationError('Not a valid datetime.')] #38

Open
chickenandpork opened this issue Apr 10, 2023 · 2 comments · May be fixed by #39
Open

ValidationError('Not a valid datetime.')] #38

chickenandpork opened this issue Apr 10, 2023 · 2 comments · May be fixed by #39

Comments

@chickenandpork
Copy link

chickenandpork commented Apr 10, 2023

Upstream seems to be stuffing a human-readable comment where a date is expected (and, you know, that date has a format)

(confirmed: no pre-existing issue)

On configuration of a new install of 2023.1.7 HA with Integration 2023.1.0, victor-smart-kill==1.1.1

Error fetching victorsmartkill data: {0: {'trapstatistics': {'last_maintenance_date': [TypeError("check_type() got an unexpected keyword argument 'argname'"), ValidationError('Not a valid datetime.')]}}}

I've confirmed credentials, they do work.

Version of Home Assistant

2023.1.7

Version of the custom_component

2023.1.0 with "victor-smart-kill==1.1.1" in requirements

Describe the bug

On configuration, and the authentication is accepted, the configuration integration periodically shows "Retrying setup: None" and seems to keep reconnecting. The remote service is online, as a manual connection does connect, and the App connects.

It seems to be that the fetched data is doing that old "we'll just record a human-readable comment there, because schema doesn't matter?" Yeah, I hate sloppy schema, totally blame the upstream:

..."last_maintenance_date":"No maintenance records exist."
...
'last_maintenance_date': [TypeError("check_type() got an unexpected keyword argument 'argname'"), ValidationError('Not a valid datetime.')]

I mean, hey, "No maintenance records exist", you mean that's not ISO8601? :-/ grrr

I do see that your schema is a union, so this is probably beyond what I can figure out for why the validation is enforcing a data time schema -- it's like it's choosing the date time rather than string, then detecting that it's not a string.

last_maintenance_date: Union[str, datetime]

Debug log

2023-04-09 20:15:46.492 DEBUG (MainThread) [httpx._client] HTTP Request: GET https://www.victorsmartkill.com/traps/ "HTTP/1.1 200 OK"
2023-04-09 20:15:46.493 DEBUG (MainThread) [victor_smart_kill._client] Response status code 200 from GET traps/ with content: b'{"count":1,"next":null,"previous":null,"results":[{"id":123456,"url":"https://www.victorsmartkill.com/traps/123456/","corruption_status":0,"operator":null,"operator_name":null,"name":"D34dMaus","ssid":"xxx","serial_number":"xxx","auto_upgrade":false,"status":0,"location":"https://www.victorsmartkill.com/locations/128640/","lat":"xxx","long":"xxx","upgrade_firmware":null,"commercial_gateway":null,"commercial_monitor_mode_enabled":false,"lorawan_app_key":"xxx","site_name":null,"floor_plan_x":0.0,"floor_plan_y":0.0,"building_name":null,"floor_name":null,"room":null,"room_name":null,"trap_type":2,"trap_type_verbose":"Mouse Trap","alerts":260298,"trapstatistics":{"id":123456,"url":"https://www.victorsmartkill.com/trapstatistics/253002/","trap":"https://www.victorsmartkill.com/traps/123456/","trap_name":"D34dMaus","kills_present":0,"install_date":"2023-01-08T00:48:37.571164Z","owner_name":"chickenandporn@gmail.com","owner_email":"chickenandporn@gmail.com","last_report_date":"2023-04-09T17:26:14.758205Z","last_kill_date":"2022-12-21T09:56:42.762351Z","temperature":0,"battery_level":41,"total_kills":3,"total_escapes":null,"rx_power_level":-60,"firmware_version":"2.0.17","trap_provisioned":true,"last_sequence_number":null,"total_retreats":null,"wireless_network_rssi":-60,"error_code":0,"send_conn_lost_nt":true,"send_empty_trap_nt":false,"board_type":"WEMT","last_maintenance_date":"No maintenance records exist.","bait_level":null,"current_bait":null,"last_bait_quantity":null}}]}'
2023-04-09 20:15:46.496 DEBUG (MainThread) [custom_components.victorsmartkill] Error getting traps from Victor Smart-Kill API: ValidationError({0: {'trapstatistics': {'last_maintenance_date': [TypeError("check_type() got an unexpected keyword argument 'argname'"), ValidationError('Not a valid datetime.')]}}})
Traceback (most recent call last):
  File "/volume1/@appdata/homeassistant/config/custom_components/victorsmartkill/__init__.py", line 178, in _get_traps
    traps = await self._api.get_traps()
  File "/volume1/@appstore/homeassistant/env/lib/python3.10/site-packages/victor_smart_kill/_api.py", line 109, in get_traps
    return await self._get_list_by_schema(TrapSchema(), "traps/")
  File "/volume1/@appstore/homeassistant/env/lib/python3.10/site-packages/victor_smart_kill/_api.py", line 49, in _get_list_by_schema
    return schema.load(
  File "/volume1/@appstore/homeassistant/env/lib/python3.10/site-packages/marshmallow_dataclass/__init__.py", line 756, in load
    all_loaded = super().load(data, many=many, **kwargs)
  File "/volume1/@appstore/homeassistant/env/lib/python3.10/site-packages/marshmallow/schema.py", line 722, in load
    return self._do_load(
  File "/volume1/@appstore/homeassistant/env/lib/python3.10/site-packages/marshmallow/schema.py", line 909, in _do_load
    raise exc
marshmallow.exceptions.ValidationError: {0: {'trapstatistics': {'last_maintenance_date': [TypeError("check_type() got an unexpected keyword argument 'argname'"), ValidationError('Not a valid datetime.')]}}}
2023-04-09 20:15:46.497 ERROR (MainThread) [custom_components.victorsmartkill] Error fetching victorsmartkill data: {0: {'trapstatistics': {'last_maintenance_date': [TypeError("check_type() got an unexpected keyword argument 'argname'"), ValidationError('Not a valid datetime.')]}}}
2023-04-09 20:15:46.498 DEBUG (MainThread) [custom_components.victorsmartkill] Finished fetching victorsmartkill data in 1.384 seconds (success: False)
2023-04-09 20:15:46.498 DEBUG (MainThread) [custom_components.victorsmartkill] Close API client.

@chickenandpork
Copy link
Author

Researching this further, I find that my HomeAssistant now has typeguard-3.0.2 which is accepted by compatibility but unfortunately metadata includes this:

(https://github.com/agronholm/typeguard/blob/master/docs/versionhistory.rst)

3.0.0 (2023-03-15)

BACKWARD INCOMPATIBLE Dropped the argname, memo, globals and locals arguments from check_type()

Smells like a "smoking gun" there but I'm unsure which project ultimately uses typeguard and causes it to be brought in.

chickenandpork added a commit to chickenandpork/victorsmartkill-homeassistant that referenced this issue Apr 16, 2023
As noted in https://github.com/agronholm/typeguard/blob/master/docs/versionhistory.rst and toreamun#38 installing `victorsmartkill` module encounters an error.  Simply blocking the behaviour of "blindly install the latest" of `typeguard` causes @toreamun's module to install and become active, immediately appearing on the "Integrations" page in HomeAssistant.
@bmos
Copy link
Contributor

bmos commented Feb 14, 2024

I'm unsure which project ultimately uses typeguard and causes it to be brought in.

I think it's this:
https://github.com/lovasoa/marshmallow_dataclass/blob/d6396c18470582a4fe5f0f2bd29ac012da4f0f1f/setup.py#L25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants