DurgNomis-drol / mytoyota

Python client for Toyota Connected Services API
MIT License
74 stars 28 forks source link

Fix: TypeError: expected string or bytes-like object, got 'list' #319

Closed CM000n closed 7 months ago

CM000n commented 7 months ago

sub expects a string for string masking, but currently it can receive any type. Therefore, we should convert the message into a string beforehand.

2024-01-27T21:12:43.276792243Z   File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 256, in _async_update_data
2024-01-27T21:12:43.276804451Z     return await self.update_method()
2024-01-27T21:12:43.276813478Z            ^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-01-27T21:12:43.276821534Z   File "/config/custom_components/toyota/__init__.py", line 102, in async_get_vehicle_data
2024-01-27T21:12:43.276830029Z     _LOGGER.debug(vehicle_informations)
2024-01-27T21:12:43.276837955Z   File "/usr/local/lib/python3.11/logging/__init__.py", line 1477, in debug
2024-01-27T21:12:43.276868291Z     self._log(DEBUG, msg, args, **kwargs)
2024-01-27T21:12:43.276877968Z   File "/usr/local/lib/python3.11/logging/__init__.py", line 1634, in _log
2024-01-27T21:12:43.276890185Z     self.handle(record)
2024-01-27T21:12:43.276902704Z   File "/usr/local/lib/python3.11/logging/__init__.py", line 1644, in handle
2024-01-27T21:12:43.276912209Z     self.callHandlers(record)
2024-01-27T21:12:43.276920238Z   File "/usr/local/lib/python3.11/logging/__init__.py", line 1706, in callHandlers
2024-01-27T21:12:43.276929011Z     hdlr.handle(record)
2024-01-27T21:12:43.276937179Z   File "/usr/local/lib/python3.11/logging/__init__.py", line 974, in handle
2024-01-27T21:12:43.276945496Z     rv = self.filter(record)
2024-01-27T21:12:43.276957643Z          ^^^^^^^^^^^^^^^^^^^
2024-01-27T21:12:43.276970582Z   File "/usr/local/lib/python3.11/logging/__init__.py", line 830, in filter
2024-01-27T21:12:43.276979936Z     result = f.filter(record)
2024-01-27T21:12:43.276987794Z              ^^^^^^^^^^^^^^^^
2024-01-27T21:12:43.276995922Z   File "/usr/local/lib/python3.11/site-packages/mytoyota/utils/logging/log_filters.py", line 16, in filter
2024-01-27T21:12:43.277008170Z     record.msg = self.mask_sensitive_data(record.msg)
2024-01-27T21:12:43.277020769Z                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-01-27T21:12:43.277030495Z   File "/usr/local/lib/python3.11/site-packages/mytoyota/utils/logging/log_filters.py", line 23, in mask_sensitive_data
2024-01-27T21:12:43.277039476Z     msg = compiled_pattern.sub("****", msg)
2024-01-27T21:12:43.277047483Z           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-01-27T21:12:43.277055417Z TypeError: expected string or bytes-like object, got 'list'
2024-01-27T21:12:43.277063292Z 2024-01-27 22:12:43 DEBUG Finished fetching toyota data in 1.984 seconds (success: False)
codecov[bot] commented 7 months ago

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (1a17a62) 80.11% compared to head (812633c) 80.11%.

Files Patch % Lines
mytoyota/utils/logging/log_filters.py 0.00% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #319 +/- ## ======================================= Coverage 80.11% 80.11% ======================================= Files 32 32 Lines 1514 1514 ======================================= Hits 1213 1213 Misses 301 301 ``` | [Flag](https://app.codecov.io/gh/DurgNomis-drol/mytoyota/pull/319/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Simon+Hansen) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/DurgNomis-drol/mytoyota/pull/319/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Simon+Hansen) | `80.11% <0.00%> (ø)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Simon+Hansen#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

CM000n commented 7 months ago

Hey @GitOldGrumpy can you please take a look and approve if it's ok with you. This solves a problem when setting up the Home Assistant integration when it has updated to MyToyota 1.3.0 in the background.