eclipse-paho / eclipse-paho/paho.mqtt.python
Message data instance types not validated when passed down in UserData -> ugly exception
- Dominant language
- Python
- Stars
- 2.4k
- Forks
- 742
- Avg merge
- 12d 48m
- Merged PRs (30d)
- 1
Description
```paho.mqtt.__version__```: 1.5.1
py version: 3.9.7
When using publish.multiple() and supplying ```"retain": str("True")``` the following ugly exception will be returned:
```
Exception has occurred: TypeError
unsupported operand type(s) for |: 'int' and 'str'
File "myfile.py", line 26, in send_stuff
publish.multiple(
...
```
was able to trace it down to:
```
Exception has occurred: TypeError
unsupported operand type(s) for |: 'int' and 'str'
File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 2507, in _send_publish
command = PUBLISH | ((dup & 0x1) << 3) | (qos << 1) | retain
...
```
so the exception happens here (v1.5.1):
https://github.com/eclipse/paho.mqtt.python/blob/42f0b13001cb39aee97c2b60a3b4807314dfcb4d/src/paho/mqtt/client.py#L2497-L2507
```retain``` in my case was ```str``` not ```bool``` and thus results in an str to int comparison
this can probably easily be fixed by adding but i'm unfamiliar with y'alls coding practices.
```and isinstance(retain, bool)``` at the end of the assert
https://github.com/eclipse/paho.mqtt.python/blob/42f0b13001cb39aee97c2b60a3b4807314dfcb4d/src/paho/mqtt/client.py#L2500-L2501
and isinstance(retain, bool)
Contributor guide
Assessment
This issue has not been assessed yet.