Webhook conditions process tags incorrectly #6697

Closed
opened 2025-12-29 19:44:06 +01:00 by adam · 3 comments
Owner

Originally created by @beginin on GitHub (Jul 20, 2022).

NetBox version

v3.2.6

Python version

3.9

Steps to Reproduce

  1. Create webhook use doc https://docs.netbox.dev/en/stable/reference/conditions/ and https://docs.netbox.dev/en/stable/additional-features/webhooks/
    {
    "id": 2,
    "url": "https://{{hide}}/api/extras/webhooks/2/",
    "display": "KVM Configuration",
    "content_types": [
    "dcim.device"
    ],
    "name": "KVM Configuration",
    "type_create": true,
    "type_update": true,
    "type_delete": false,
    "payload_url": "https://{{hide}}",
    "enabled": true,
    "http_method": "POST",
    "http_content_type": "application/json",
    "additional_headers": "",
    "body_template": "{"token": "secret",\r\n"ref": "main"}",
    "secret": "",
    "conditions": {
    "and": [
    {
    "op": "contains",
    "attr": "tags",
    "value": "kvm_configuration_needed"
    }
    ]
    },
    "ssl_verification": false,
    "ca_file_path": null,
    "created": "2022-06-14T06:44:34.198779Z",
    "last_updated": "2022-07-20T10:52:47.492639Z"
    }

Expected Behavior

  1. When I updates com.device I expect get request https://{{hide}}

I try to debug and found this code witch work incorrectly
https://github.com/netbox-community/netbox/blob/v3.2.6/netbox/extras/conditions.py#L106

I sniffed vars
self.value is 'kvm_configuration_needed'
value is [OrderedDict([('id', 75), ('url', '/api/extras/tags/75/'), ('display', 'kvm_configuration_needed'), ('name', 'kvm_configuration_needed'), ('slug', 'kvm_configuration_needed'), ('color', 'ff9800')]), OrderedDict([('id', 77), ('url', '/api/extras/tags/77/'), ('display', 'kvm_failed'), ('name', 'kvm_failed'), ('slug', 'kvm_failed'), ('color', 'f44336')])]
value is list of dictionaries

condition self.value in value will be always false for list of dictionaries.

Observed Behavior

Get request https://{{hide}} is not happening

Originally created by @beginin on GitHub (Jul 20, 2022). ### NetBox version v3.2.6 ### Python version 3.9 ### Steps to Reproduce 1. Create webhook use doc https://docs.netbox.dev/en/stable/reference/conditions/ and https://docs.netbox.dev/en/stable/additional-features/webhooks/ { "id": 2, "url": "https://{{hide}}/api/extras/webhooks/2/", "display": "KVM Configuration", "content_types": [ "dcim.device" ], "name": "KVM Configuration", "type_create": true, "type_update": true, "type_delete": false, "payload_url": "https://{{hide}}", "enabled": true, "http_method": "POST", "http_content_type": "application/json", "additional_headers": "", "body_template": "{\"token\": \"secret\",\r\n\"ref\": \"main\"}", "secret": "", "conditions": { "and": [ { "op": "contains", "attr": "tags", "value": "kvm_configuration_needed" } ] }, "ssl_verification": false, "ca_file_path": null, "created": "2022-06-14T06:44:34.198779Z", "last_updated": "2022-07-20T10:52:47.492639Z" } ### Expected Behavior 1. When I updates com.device I expect get request https://{{hide}} I try to debug and found this code witch work incorrectly https://github.com/netbox-community/netbox/blob/v3.2.6/netbox/extras/conditions.py#L106 I sniffed vars self.value is 'kvm_configuration_needed' value is [OrderedDict([('id', 75), ('url', '/api/extras/tags/75/'), ('display', 'kvm_configuration_needed'), ('name', 'kvm_configuration_needed'), ('slug', 'kvm_configuration_needed'), ('color', 'ff9800')]), OrderedDict([('id', 77), ('url', '/api/extras/tags/77/'), ('display', 'kvm_failed'), ('name', 'kvm_failed'), ('slug', 'kvm_failed'), ('color', 'f44336')])] value is list of dictionaries condition self.value in value will be always false for list of dictionaries. ### Observed Behavior Get request https://{{hide}} is not happening
adam added the type: bug label 2025-12-29 19:44:06 +01:00
adam closed this issue 2025-12-29 19:44:06 +01:00
Author
Owner

@DanSheps commented on GitHub (Jul 21, 2022):

We need better reproduction steps and a better expected/observed behaviour.

If you want to add the extra information, please do so as a comment, but right now, it is hard to determine what is a problem and what isn't

@DanSheps commented on GitHub (Jul 21, 2022): We need better reproduction steps and a better expected/observed behaviour. If you want to add the extra information, please do so as a comment, but right now, it is hard to determine what is a problem and what isn't
Author
Owner

@beginin commented on GitHub (Jul 21, 2022):

In a result, when device's tags are changed webhook with appropriate condition gets url but it doesn't work.

  1. I created the webhook with condition "and": [{"op": "contains","attr": "tags","value": "kvm_configuration_needed"}]}
  2. I added tag "kvm_configuration_needed" to a device and nothing happend.
  3. The webhook without condition got url as I expected
@beginin commented on GitHub (Jul 21, 2022): In a result, when device's tags are changed webhook with appropriate condition gets url but it doesn't work. 1. I created the webhook with condition "and": [{"op": "contains","attr": "tags","value": "kvm_configuration_needed"}]} 2. I added tag "kvm_configuration_needed" to a device and nothing happend. 3. The webhook without condition got url as I expected
Author
Owner

@jeremystretch commented on GitHub (Jul 26, 2022):

This isn't a bug, but rather a limitation of how conditions are evaluated. If you inspect the webhook data, you'll see that the tags field is a list of dictionaries, each of which represents an individual tag. So, we cannot use the contains operator referencing a string, because all of the items are dictionaries.

I'm going to close this out as the reported behavior, while annoying, is expected. You're welcome to open a new feature request if you'd like to propose a specific change to the webhook conditions logic that would make this easier to accomplish.

@jeremystretch commented on GitHub (Jul 26, 2022): This isn't a bug, but rather a limitation of how conditions are evaluated. If you inspect the webhook data, you'll see that the `tags` field is a list of dictionaries, each of which represents an individual tag. So, we cannot use the `contains` operator referencing a string, because all of the items are dictionaries. I'm going to close this out as the reported behavior, while annoying, is expected. You're welcome to open a new [feature request](https://github.com/netbox-community/netbox/issues/new?assignees=&labels=type%3A+feature&template=feature_request.yaml) if you'd like to propose a specific change to the webhook conditions logic that would make this easier to accomplish.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#6697