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

[paho-mqtt] DeprecationWarning: Callback API version 1 is deprecated, update to latest version #24

Open
parrotrueper opened this issue Oct 14, 2024 · 7 comments

Comments

@parrotrueper
Copy link

Given the following test

import pytest
from pytest_mqtt.model import MqttMessage

@pytest.fixture
def configure_capmqtt_decode_utf8(pytestconfig):
    pytestconfig.option.capmqtt_decode_utf8 = True


def test_basic_submit_text_receive_text_config(configure_capmqtt_decode_utf8,  capmqtt):
    """
    Basic submit/receive roundtrip, with text payload (`str`).

    By using the global `capmqtt_decode_utf8` config option, the payloads
    will be received as `str`, after decoding them from `utf-8`.
    """

    # Submit two MQTT messages.
    capmqtt.publish(topic="foo", payload="bar")
    capmqtt.publish(topic="baz", payload="qux")

    # Demonstrate the `messages` property.
    assert capmqtt.messages == [
        MqttMessage(topic="foo", payload="bar", userdata=None),
        MqttMessage(topic="baz", payload="qux", userdata=None),
    ]

    # Demonstrate the `records` property.
    assert capmqtt.records == [
        ("foo", "bar", None),
        ("baz", "qux", None),

running with:

python -m pytest -x --full-trace --junitxml=./report.xml --mqtt-host=192.168.1.123 --mqtt-port=1883

The test passes but I get the following warning:

/usr/local/lib/python3.11/site-packages/pytest_mqtt/capmqtt.py:38: DeprecationWarning: Callback API version 1 is deprecated, update to latest version 
self.client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1)

Sorry if this is a silly question, but how do I tell capmqtt to use the paho-mqtt Version 2 for the tests?

@amotl
Copy link
Member

amotl commented Oct 19, 2024

Hi. It looks like compatibility with paho-mqtt version 2 has been addressed already.

However, support for version 2 might be incomplete, or not thorough, yet.

@amotl
Copy link
Member

amotl commented Oct 19, 2024

However, support for version 2 might be incomplete, or not thorough, yet.

/usr/local/lib/python3.11/site-packages/pytest_mqtt/capmqtt.py:38: DeprecationWarning: Callback API version 1 is deprecated, update to latest version 
self.client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1)

I see. Line 38 instructs the library to use mqtt.CallbackAPIVersion.VERSION1.

# paho-mqtt 2.x
self.client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1)

Sorry if this is a silly question, but how do I tell capmqtt to use the paho-mqtt Version 2 for the tests?

So, I guess you are already using paho-mqtt version 2, but still the "Callback API version 1". I think you can do nothing about the situation, other than silencing the warning messages. This, on the other hand, may also be conducted on behalf of pytest-mqtt already.

In the mid-term, pytest-mqtt must update how it uses the callback api of paho-mqtt, in order to adhere to the convention/specification of the "Callback API version 2".

@amotl amotl changed the title capmqtt.py:38: DeprecationWarning DeprecationWarning: Callback API version 1 is deprecated, update to latest version Oct 19, 2024
@amotl amotl changed the title DeprecationWarning: Callback API version 1 is deprecated, update to latest version [paho-mqtt] DeprecationWarning: Callback API version 1 is deprecated, update to latest version Oct 19, 2024
@amotl
Copy link
Member

amotl commented Oct 19, 2024

Hi again. bea0d52 makes the procedure ignore the deprecation warning, until the transition to Callback API v2 has been concluded. Do you think this will help you already?

pytest-mqtt 0.4.3 has just been released and published to PyPI, including this update.

@hyperspacex2
Copy link

As I see in Paho Migrations Doc the new callback uses reason_code (inst of ReasonCode) istead of an integer rc. An update to VERSION2 should be as simple as updating the callback functions on_connect and on_subscribe.

on_connect:

def on_connect(self, client, userdata, flags, rc):

would change to
def on_connect(self, client, userdata, flags, reason_code, properties):

on_subscribe:

def on_subscribe(self, client, userdata, mid, granted_qos, properties=None):

would change to
def on_subscribe(self, client, userdata, mid, reason_codes, properties):

As I see it this would be a minor change as rc granted_qos are not actually used in those callbacks.

Any reason why not to migrate to VERSION2 now?

@parrotrueper
Copy link
Author

Would be great if the default was VERSION2 failing that an argument to set it.

@amotl
Copy link
Member

amotl commented Oct 28, 2024

Thanks for sharing your investigations. Would you be up for submitting a patch based on your observations, @hyperspacex2? It will be well appreciated.

@hyperspacex2
Copy link

Thanks for sharing your investigations. Would you be up for submitting a patch based on your observations, @hyperspacex2? It will be well appreciated.

Sure. See PR #28

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

No branches or pull requests

3 participants