eclipse-paho / paho.mqtt.python

paho.mqtt.python
Other
2.2k stars 721 forks source link

Since version 2.0 calling client.reinitialise() raise RuntimeError: Unsupported callback API version #824

Open Mips2648 opened 7 months ago

Mips2648 commented 7 months ago

Bug Description

Since version 2.0, as argument "callback_api_version" is require, calling client.reinitialise() raise RuntimeError: Unsupported callback API version because this method do not provide it

current code:

    def reinitialise(
        self,
        client_id: str = "",
        clean_session: bool = True,
        userdata: Any = None,
    ) -> None:
        self._reset_sockets()

        self.__init__(client_id, clean_session, userdata)  # type: ignore[misc]

I suppose this could be changed to

self.__init__(self._callback_api_version, client_id, clean_session, userdata)  # type: ignore[misc]

Reproduction

Simply init a client then call reinitialise()

mqtt_client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
mqtt_client.username_pw_set(username="user", password="pass")
mqtt_client.connect(...)
mqtt_client.loop_start()

...

mqtt_client.reinitialise()

Environment

henryptung commented 7 months ago

The API break was so wide-impact it broke its own codebase? Oof.