netbox icon indicating copy to clipboard operation
netbox copied to clipboard

Strange behaviour with generated >3 VLANs table for interfaces

Open Azmodeszer opened this issue 1 year ago • 1 comments

Deployment Type

Self-hosted

Triage priority

N/A

NetBox Version

v4.1.4

Python Version

3.11

Steps to Reproduce

I'm seeing some weird behaviour with the new feature as implemented per #17655. I can't give exact guaranteed reproduction steps, because it might be something specific to my database that I haven't figured out yet, but basically:

  1. Find an interface with more than 3 tagged VLANs and 1 untagged VLAN. (created before the update(?), see Observed Behavior)
  2. Click on the created link for the tagged VLANs (of the form /ipam/vlans/?interface_id=<ID>).

Expected Behavior

Tagged VLANs for that interface are shown correctly.

Observed Behavior

What I am seeing is some of the tagged VLANs being listed multiple times (and the untagged VLAN showing up as well, which I guess is to be expected). I've tried to reproduce it with new VLANs created after the update to 4.1.4 and it seems to work as expected with those (some "older" VLANs are also only showing up once, however, so it might not be related to that at all), but when I attach a certain existing VLAN as tagged to the interface it results in multiple redundant rows again.

image

Azmodeszer avatar Oct 16 '24 09:10 Azmodeszer

I can confirm that we see the same behaviour.

cs-1 avatar Oct 17 '24 07:10 cs-1

If only Q(interfaces_as_tagged=value) or Q(interfaces_as_untagged=value) is used, it looks fine. But both combined messes up the joins. The query ends being:

SELECT
"ipam_vlan"."id", "ipam_vlan"."created", "ipam_vlan"."last_updated", "ipam_vlan"."custom_field_data",
"ipam_vlan"."description", "ipam_vlan"."comments", "ipam_vlan"."site_id", "ipam_vlan"."group_id",
"ipam_vlan"."vid", "ipam_vlan"."name", "ipam_vlan"."tenant_id", "ipam_vlan"."status", "ipam_vlan"."role_id"
FROM "ipam_vlan"
LEFT OUTER JOIN "dcim_interface_tagged_vlans" ON ("ipam_vlan"."id" = "dcim_interface_tagged_vlans"."vlan_id")
LEFT OUTER JOIN "dcim_interface" T4 ON ("ipam_vlan"."id" = T4."untagged_vlan_id")
WHERE ("dcim_interface_tagged_vlans"."interface_id" = 385 OR T4."id" = 385)
ORDER BY "ipam_vlan"."vid" ASC;

If and "dcim_interface_tagged_vlans"."interface_id" = 385 is added to the first JOIN the result looks fine - but I don't know how to do that in Django.

But a solution seems is to add distinct (in netbox/ipam/filtersets.py):

        return queryset.filter(
            Q(interfaces_as_tagged=value) |
            Q(interfaces_as_untagged=value)
        ).distinct()

See this commit: https://github.com/thordreier/netbox/commit/ee1de426074a28672fbc082f99348891a5df302d

thordreier avatar Oct 30 '24 14:10 thordreier

Couldn't the link just go to the interface page and focus the VLAN table? I don't see why it has to go to the VLAN list + filter there.

salfers avatar Nov 04 '24 13:11 salfers

Couldn't the link just go to the interface page and focus the VLAN table? I don't see why it has to go to the VLAN list + filter there.

That was also the first implentation in https://github.com/netbox-community/netbox/pull/17662 - but it was decided to change it.

thordreier avatar Nov 05 '24 08:11 thordreier

See this commit: thordreier@ee1de42

@thordreier would you be open to have this issue assigned to you and open a PR since you seem to already have the fix?

jsenecal avatar Nov 13 '24 14:11 jsenecal

@jsenecal yeah, that's fine

thordreier avatar Nov 13 '24 17:11 thordreier

@thordreier assigned it to you. Thank you.

arthanson avatar Dec 03 '24 17:12 arthanson

@thordreier do you still intend to work on this issue?

jeremystretch avatar Dec 26 '24 15:12 jeremystretch

Sorry. I forgot about this issue. I've created the pull request now.

thordreier avatar Dec 27 '24 19:12 thordreier