Adding the untagged_vlan property to dcim.interface using the API that isn't in mode tagged fails without error #10134

Closed
opened 2025-12-29 21:27:17 +01:00 by adam · 4 comments
Owner

Originally created by @sol1-matt on GitHub (Aug 23, 2024).

Originally assigned to: @DanSheps on GitHub.

Deployment Type

Self-hosted

NetBox Version

v4.0.5, v4.0.9

Python Version

3.10

Steps to Reproduce

  1. Create site
  2. Create vlan at site, don't set 802.1Q Mode (leave it unset)
  3. Create device at site
  4. Create interface on device
  5. Try adding the vlan to the interface using the netbox api with the following options
    1. dict containing dict {'untagged_vlan':{vid, name, site}} values from vlan
    2. dict containing dict {'untagged_vlan':{id}}, value from vlan
    3. dict contaning value {'untagged_vlan': id} value from vlan

Test script using pynetbox

pip install logruru pynetbox
loguru because I like the colours

import pynetbox
import requests

from loguru import logger

netbox_url = "https://demo.netbox.dev"
token = "I assume my token will be deleted so add your own :)"
headers = {
    'Authorization': f'Token {token}',
    'Content-Type': 'application/json',
    'Accept': 'application/json',
}

device_id = 129 
iface_id = 1776
vlan_id = 21

nb = pynetbox.api(netbox_url, token=token)

device = nb.dcim.devices.get(id=device_id)
logger.debug(dict(device))

iface = nb.dcim.interfaces.get(id=iface_id)
logger.debug(dict(iface))

vlan = nb.ipam.vlans.get(id=vlan_id)
logger.debug(dict(vlan))



## Pynetbox tests
try:
    logger.error("pynetbox: API doc required vid and name")
    logger.info(f"loaded: {iface.untagged_vlan}")
    iface.untagged_vlan = {"vid": vlan.vid, "name": vlan.name, "site": vlan.site.id}
    logger.info(f"local: {iface.untagged_vlan}")
    iface.save()
    iface = nb.dcim.interfaces.get(id=iface_id)
    logger.info(f"reloaded: {iface.untagged_vlan}")
except Exception as e:
    logger.critical(e)

try:
    logger.error("pynetbox: vlan id")
    iface.untagged_vlan = {"id": vlan.id}
    logger.info(f"local: {iface.untagged_vlan}")
    iface.save()
    iface = nb.dcim.interfaces.get(id=iface_id)
    logger.info(f"reloaded: {iface.untagged_vlan}")
except Exception as e:
    logger.critical(e)

try:
    logger.error("pynetbox: vlan object")
    iface.untagged_vlan = vlan
    logger.info(f"local: {iface.untagged_vlan}")
    iface.save()
    iface = nb.dcim.interfaces.get(id=iface_id)
    logger.info(f"reloaded: {iface.untagged_vlan}")
except Exception as e:
    logger.critical(e)

Expected Behavior

The api call would return a error message telling me I can't add a untagged_vlan with first setting a 802.1Q Mode.

Observed Behavior

The api works successfully and the interface object is returned unchanged.

Originally created by @sol1-matt on GitHub (Aug 23, 2024). Originally assigned to: @DanSheps on GitHub. ### Deployment Type Self-hosted ### NetBox Version v4.0.5, v4.0.9 ### Python Version 3.10 ### Steps to Reproduce 1. Create site 2. Create vlan at site, don't set 802.1Q Mode (leave it unset) 3. Create device at site 4. Create interface on device 5. Try adding the vlan to the interface using the netbox api with the following options 1. dict containing dict `{'untagged_vlan':{vid, name, site}}` values from vlan 2. dict containing dict `{'untagged_vlan':{id}}`, value from vlan 3. dict contaning value `{'untagged_vlan': id}` value from vlan ## Test script using pynetbox `pip install logruru pynetbox` loguru because I like the colours ``` import pynetbox import requests from loguru import logger netbox_url = "https://demo.netbox.dev" token = "I assume my token will be deleted so add your own :)" headers = { 'Authorization': f'Token {token}', 'Content-Type': 'application/json', 'Accept': 'application/json', } device_id = 129 iface_id = 1776 vlan_id = 21 nb = pynetbox.api(netbox_url, token=token) device = nb.dcim.devices.get(id=device_id) logger.debug(dict(device)) iface = nb.dcim.interfaces.get(id=iface_id) logger.debug(dict(iface)) vlan = nb.ipam.vlans.get(id=vlan_id) logger.debug(dict(vlan)) ## Pynetbox tests try: logger.error("pynetbox: API doc required vid and name") logger.info(f"loaded: {iface.untagged_vlan}") iface.untagged_vlan = {"vid": vlan.vid, "name": vlan.name, "site": vlan.site.id} logger.info(f"local: {iface.untagged_vlan}") iface.save() iface = nb.dcim.interfaces.get(id=iface_id) logger.info(f"reloaded: {iface.untagged_vlan}") except Exception as e: logger.critical(e) try: logger.error("pynetbox: vlan id") iface.untagged_vlan = {"id": vlan.id} logger.info(f"local: {iface.untagged_vlan}") iface.save() iface = nb.dcim.interfaces.get(id=iface_id) logger.info(f"reloaded: {iface.untagged_vlan}") except Exception as e: logger.critical(e) try: logger.error("pynetbox: vlan object") iface.untagged_vlan = vlan logger.info(f"local: {iface.untagged_vlan}") iface.save() iface = nb.dcim.interfaces.get(id=iface_id) logger.info(f"reloaded: {iface.untagged_vlan}") except Exception as e: logger.critical(e) ``` ### Expected Behavior The api call would return a error message telling me I can't add a untagged_vlan with first setting a 802.1Q Mode. ### Observed Behavior The api works successfully and the interface object is returned unchanged.
adam added the type: bugstatus: acceptedseverity: low labels 2025-12-29 21:27:17 +01:00
adam closed this issue 2025-12-29 21:27:17 +01:00
Author
Owner

@sol1-matt commented on GitHub (Aug 23, 2024):

This started out as a bug report on the api not working until I figured out I needed to set the 802.1Q Mode to tagged on the interface to be able to save to the untagged_vlan field.

That was annoying enough and took enough time to figure out that I still submitted issue so anybody else automating vlan creation has a reference even if it doesn't get fixed.

working example is

    iface.mode = 'tagged'
    iface.untagged_vlan = {"vid": vlan.vid, "name": vlan.name, "site": vlan.site.id}
    iface.save()
@sol1-matt commented on GitHub (Aug 23, 2024): This started out as a bug report on the api not working until I figured out I needed to set the 802.1Q Mode to `tagged` on the interface to be able to save to the `untagged_vlan` field. That was annoying enough and took enough time to figure out that I still submitted issue so anybody else automating vlan creation has a reference even if it doesn't get fixed. working example is ``` iface.mode = 'tagged' iface.untagged_vlan = {"vid": vlan.vid, "name": vlan.name, "site": vlan.site.id} iface.save() ```
Author
Owner

@jeremystretch commented on GitHub (Aug 26, 2024):

This seems very similar to the issue captured under #15924 and can probably be addressed in the same manner. @DanSheps do you think it makes sense to merge these?

@jeremystretch commented on GitHub (Aug 26, 2024): This seems very similar to the issue captured under #15924 and can probably be addressed in the same manner. @DanSheps do you think it makes sense to merge these?
Author
Owner

@DanSheps commented on GitHub (Aug 27, 2024):

Good catch, I will implement the fix in the same PR since they are so closely related

@DanSheps commented on GitHub (Aug 27, 2024): Good catch, I will implement the fix in the same PR since they are so closely related
Author
Owner

@jeremystretch commented on GitHub (Aug 27, 2024):

Folding this into #15924, for which PR #17211 has been submitted.

@jeremystretch commented on GitHub (Aug 27, 2024): Folding this into #15924, for which PR #17211 has been submitted.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10134