-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Missing error message when Tagged VLAN with incompatible Site is set #3589
Comments
One issue is that the list of VLANs is not currently filtered by site/group assignment. This would actually be very difficult to implement fully given the current state of logic around API-based select fields. It would probably be best handled by introducing a new filter that returns all available VLANs for a given site (e.g. The other issue is that when an invalid VLAN is selected, we do not raise a validation error. I'm going to say that the scope of this particular bug report should be limited to this second issue only. |
I thought we did this in the clean() logic, did we not? |
If we do, it's not working. I was able to confirm the reported bug. |
Just checked, it only checks for untagged vlans. |
I am going to give this a stab and see if there is a way to have it perform more then one query for the API as well. |
@jeremystretch can this be resolved the same way as If I'm understanding this correctly, the list of VLAN choices should be limited to global (null) and to the site of the device. I've seen the logic in Line 2230 in 8a4293a
but functionally, the result will be the same because
Stated differently
Basically, the restrictions on the VLAN's site and group membership were already applied during the creation of the VLAN. And if I'm not mistaken, the filtering logic for I've tested the behaviour of the two things above ( |
Turns out that because the tagged VLANs aren't cleaned, the update goes through to the database and is visible through the API. The VLAN is not present in the edit page so you can still (unknowingly) update it to a clean state by not including any of the invalid choices. At any rate, I'm working on a PR for this. |
@jeremystretch I've got the validation fix ready, but in order to only show the valid choices in the VLAN selection, I'm gonna need to modify how |
The filtering logic needs to remain in place for init(). If not, you will have a timeout if you have a large number of vlans. If you want to start a PR for this, I can take a look at it more too. |
@DanSheps, I see the pointing you're raising. I'll update it. The current state is that it loads the valid options but they will not be seen because of the widget. <select name="tagged_vlans" class="netbox-select2-api form-control select2-hidden-accessible" data-url="/api/ipam/vlans/" data-full="" display-field="display_name" data-multiple="1" placeholder="None" id="id_tagged_vlans" multiple="" tabindex="-1" aria-hidden="true">
<optgroup label="Global">
<option value="2" selected="">2 (vlan2)</option>
</optgroup>
<optgroup label="global">
</optgroup>
<optgroup label="London">
<option value="1">1 (vlan1)</option>
</optgroup>
</select> If you click on the select, the By removing the code, it is loading all of the VLANs. <select name="tagged_vlans" class="netbox-select2-api form-control select2-hidden-accessible" data-url="/api/ipam/vlans/" data-full="" display-field="display_name" data-additional-query-param-site_id="null" data-multiple="1" placeholder="None" id="id_tagged_vlans" multiple="" tabindex="-1" aria-hidden="true">
<option value="3">3 (vlan3)</option>
<option value="4">100 (100)</option>
<option value="1">1 (vlan1)</option>
<option value="2" selected="">2 (vlan2)</option>
</select> It's odd that it would load all of the options, but I suppose that's because it inherits from Django's An alternative would to change the widget to
What I'm currently trying for this issue is including two |
@DanSheps #3813 will solve the unnecessary load of options, so there won't be any need for the the manual choices on the API-based select field (only selected values are loaded). The current untagged and tagged VLANs select fields are still not filtering the VLAN's site to current or global, so that's still left to be done. |
Found a workaround if we want to avoid modifying the existing code for handling additional parameters. For the widget, add the additional_query_params={
'site_id': 'null'
} In the init, add the following self.fields['untagged_vlan'].widget.attrs['1-data-additional-query-param-site_id'] = self.parent_obj.site.pk
self.fields['tagged_vlans'].widget.attrs['1-data-additional-query-param-site_id'] = self.parent_obj.site.pk This works around the current code in forms.js. Specifically if (attr.name.includes("data-additional-query-param-")){
var param_name = attr.name.split("data-additional-query-param-")[1]; I'll add this to a PR and we'll see how we go about this. Assuming we get more instances of this, it might be better to find a long-term way of adding multiple values to the same parameter. |
Fixes #3589: Interface VLAN filtering
Environment
Steps to Reproduce
Expected Behavior
An Error message.
Observed Behavior
No error message, and the VLAN does not get set.
Comment
A error message is correctly produced if the Mode is Access and the VLAN is selected in the Untagged input field instead. Then we get "The untagged VLAN (123) must belong to the same site as the interface's parent device/VM, or it must be global". The same message should be show there too.
The text was updated successfully, but these errors were encountered: