taverntesting/tavern

Unable to use external function in MQTT publish

samunnat opened this issue · 3 comments

I tried using an external function in a MQTT publish request, and the function wasn't getting evaluated.

My request looks like this:

  - id: publish_thing_1
    name: Publish thing 1
    mqtt_publish:
      topic: &ping_topic '/device/123/ping'
      qos: 1
      json:
        $ext: 
          function: utils.testing_utils:my_function
        thing_1: abc
    mqtt_response:
      topic: *ping_topic
      json:
        header: test
        thing_1: abc
      timeout: 5
      qos: 1

It looks like the line below in request.py

update_from_ext(publish_args, ["json"], test_block_config)

should be

update_from_ext(publish_args, ["payload"], test_block_config)

instead, since publish_args looks like this:

{'topic': '/device/123/ping', 'qos': 1, 'payload': '{"$ext": {"function": "utils.testing_utils:my_function"}, "thing_1": "abc"}'}

Note that the payload value is a string, which prevents external function evaluation even after I do the update_from_ext change. Before I go down the rabbit hole too much, I wanted to confirm that I've configured the request properly, and that this feature is expected to work after this PR.

It seems like ext functions weren't being used properly in MQTT, I've opened a PR to try and fix it

Should be fixed in 2.0.4

Awesome, thanks for the quick fix.