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
eliminate shadow fields and correct filter names #2847
eliminate shadow fields and correct filter names #2847
Conversation
@@ -2253,6 +2253,11 @@ class DeviceFilterForm( | |||
label="Has a primary IP", | |||
widget=StaticSelect2(choices=BOOLEAN_WITH_BLANK_CHOICES), | |||
) | |||
has_interfaces = forms.NullBooleanField( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have to add this to make DynamicGroupModelTest pass since DG derives the filters from filterset_form.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something seems off here. You didn't change the has_interfaces
filter definition, so why did this need to be added? And are there a bunch of other filters that also need to be added/updated in the forms now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
has_interfaces
is a special case, since it was the one that sparked the “we shouldn’t shadow related names and change their intent/type” initiative when it was originally named interfaces
. All of the other has_foo
filters were added later if they didn't already exist. For DeviceFilterSet
, however, I think this is the only one that didn't already have a has_foo
form field because it would have been confusing in v1.x.
nautobot/core/tests/test_graphql.py
Outdated
@@ -1210,7 +1210,7 @@ def test_query_device_role_filter(self): | |||
# pylint: disable=consider-using-f-string | |||
""" | |||
query { | |||
devices(role: "%s") { | |||
devices(device_role: "%s") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering - with the proposed shift to a generic Role
model replacing DeviceRole
and others, maybe this should stay as role
? Food for thought.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seconded.
nautobot/dcim/filters.py
Outdated
queryset=RackGroup.objects.all(), | ||
field_name="rack__group", | ||
label="Rack group (ID)", | ||
label="Rack group (slug or ID)", | ||
) | ||
rack_id = django_filters.ModelMultipleChoiceFilter( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should rack
become a NaturalKeyOrPKMultipleChoiceFilter?
nautobot/dcim/filters.py
Outdated
@@ -1002,11 +931,10 @@ class DeviceFilterSet( | |||
queryset=Cluster.objects.all(), | |||
label="VM cluster (ID)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should cluster
become a NaturalKeyOrPKMultipleChoiceFilter?
@@ -1002,11 +931,10 @@ class DeviceFilterSet( | |||
queryset=Cluster.objects.all(), | |||
label="VM cluster (ID)", | |||
) | |||
model = django_filters.ModelMultipleChoiceFilter( | |||
field_name="device_type__slug", | |||
model = NaturalKeyOrPKMultipleChoiceFilter( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should become device_type
, I believe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it does have a device_type
filter defined on line 912? Could this be something different or a duplicate? Kinda looks like a duplicate.
nautobot/dcim/filters.py
Outdated
queryset=SecretsGroup.objects.all(), | ||
to_field_name="slug", | ||
label="Secrets group (slug)", | ||
label="Secrets group (slug or ID)", | ||
) | ||
virtual_chassis_id = django_filters.ModelMultipleChoiceFilter( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
virtual_chassis
as NaturalKeyOrPKMultipleChoiceFilter?
nautobot/dcim/filters.py
Outdated
@@ -1156,23 +1118,19 @@ class DeviceComponentFilterSet(CustomFieldModelFilterSet): | |||
to_field_name="slug", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not changing the region
and site
filters? (Ah, I see - that's in #2846. It would be good to update the description of this PR to clearly indicate what it is and is not targeting for change.)
nautobot/dcim/filters.py
Outdated
to_field_name="slug", | ||
label="Role (slug)", | ||
) | ||
role = NaturalKeyOrPKMultipleChoiceFilter(queryset=RackRole.objects.all(), label="Role (slug or ID)") | ||
serial = django_filters.CharFilter(lookup_expr="iexact") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't serial
need to be changed to a MultiValueCharFilter?
@@ -552,22 +526,17 @@ class RackReservationFilterSet(NautobotFilterSet, TenancyFilterSet): | |||
field_name="rack__group", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
elimination of group_id
filter?
to_field_name="slug", | ||
label="Manufacturer (slug)", | ||
manufacturer = NaturalKeyOrPKMultipleChoiceFilter( | ||
queryset=Manufacturer.objects.all(), label="Manufacturer (slug or ID)" | ||
) | ||
has_devices = RelatedMembershipBooleanFilter( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addition of devices
and virtual_machines
filters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the scope of the PR is to fix incorrect filters and not adding missing ones. I will elaborate this in the description.
@@ -2253,6 +2253,11 @@ class DeviceFilterForm( | |||
label="Has a primary IP", | |||
widget=StaticSelect2(choices=BOOLEAN_WITH_BLANK_CHOICES), | |||
) | |||
has_interfaces = forms.NullBooleanField( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something seems off here. You didn't change the has_interfaces
filter definition, so why did this need to be added? And are there a bunch of other filters that also need to be added/updated in the forms now?
nautobot/dcim/filters.py
Outdated
@@ -254,7 +248,7 @@ class SiteFilterSet(NautobotFilterSet, TenancyFilterSet, StatusModelFilterSetMix | |||
label="Time zone", | |||
null_value="", | |||
) | |||
tag = TagFilter() | |||
tags = TagFilter() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please humor me and remove this definition from this filterset and see if it behaves the same?
It's what I referenced yesterday in standup, that TaggableManager
fields are already automatically mapped to TagFilter
so I'm hoping it should Just Work™. See:
nautobot/nautobot/utilities/filters.py
Line 570 in 4168c37
TaggableManager: {"filter_class": TagFilter}, |
In other words, as long as "tags" is provided in Meta.fields
for the filterset, I'm pretty certain that it won't need to be overloaded on the filterset class itself. Thanks!
In the nautobot/extras/tests/test_dynamicgroups.py
nautobot/dcim/filters.py
|
…ltiValueCharFilter
…of NaturalKeyOrMultipleChoiceField
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have some minor asks for style, but this looks good-to-go! 🚢 🇮🇹
…ittest using pass_throgh_ports filter that no longer exists
Closes: #2804
What's Changed
This PR is dedicated to:
NaturalKeyOrPKMultipleChoiceFilter
interfaces
should not be the same ashas_interfaces
and should be its ownNaturalKeyOrPKMultipleChoiceFilter
See also related PRs -
#2845 -- closed as duplicate to #2798
#2846 -- collapse
site_id
andregion_id
tosite
andregion
NaturalKeyOrPKMultipleChoiceFilter
.TODO