Repository: netbox-community/netbox

Issue:
Device filter with non-racked devices
### NetBox version

v3.2.4

### Python version

3.10

### Steps to Reproduce

1. Go to a location with more than 10 non-racked devices
2. Click **View full list**

### Expected Behavior

The filter should show non-racked devices

### Observed Behavior

A view of devices with the filters for *Location: foobar* and *Rack: None* show no devices


Discussion:
Thank you for opening a bug report. I was unable to reproduce the reported behavior on NetBox v3.2.4. Please re-confirm the reported behavior on the current stable release and adjust your post above as necessary. Remember to provide detailed steps that someone else can follow using a clean installation of NetBox to reproduce the issue. Remember to include the steps taken to create any initial objects or other data.
I might not have described it correctly, but I did take a recording here:
![netbox](https://user-images.githubusercontent.com/1351571/172915019-2255aa65-8a18-4839-b7da-e09777c83c25.gif)


I'm still not able to reproduce this on v3.2.4. Clicking the "View full list" link takes me to the properly filtered devices list, which returns the expected results.
I think I see the issue now. This site, location, rack, and devices are "Planned". When I go into one of the devices, it actually has a Rack set, so really, it seems that the devices shouldn't appear in the "Non-Racked Devices" short list. It correctly doesn't appear in the full list.
Devices will appear in the "non-racked" list so long as they don't have a face/position set. Is that the case for you?
I have set half of them to have a face (they're all PDUs) and the other half left blank. They appear in the summary list of a site/location, but not in the full list.
> I have set half of them to have a face (they're all PDUs) and the other half left blank. They appear in the summary list of a site/location, but not in the full list.


This is why it is important to have full steps, starting from creation, for us to reproduce issues.

@jeremystretch I think the issue is they are in the "non-racked" list under site but are in a rack, just without a face/position, so when you view the full list, you don't see the devices.  Reproduced here: https://demo.netbox.dev/dcim/sites/44/ (unless someone deletes it).

Steps to recreate:

1. Create a site
2. Create a rack in the site
3. Create a device in the site and rack but without a position or face
4. Repeat last step at least 10 more times
5. View site
6. Follow link to view "Non-racked" devices
Ah, yeah I think we've overloaded the term "non-racked" to mean both not assigned to a rack, and not assigned to a position/face, where arguably the former is more correct. It looks like the same template is used for the site, location, and rack views. We should standardize on the behavior for sites & locations, and use a different term for the rack view.
Non-racked for sites & locations

For racks, I can think of:

* Unpositioned (clunky)
* Unassigned (Ambiguous)
* Non-mounted (Could be confusing)

Any other thoughts?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. **Do not** attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Here is the approach I am going to take with this:

* Modify the query on sites & locations to only return Rack=None devices
* Leave the naming as-is for now for the following reason:
  * When looking at sites/locations, typically that person looking at the word "non-racked" is going to think: any device not in a rack
  * When looking at a rack itself, typicially someone looking at the word "non-racked" is going to think: any devicie in the rack not with a fixed rack unit position

Resolving patch:
diff --git a/netbox/dcim/views.py b/netbox/dcim/views.py
--- a/netbox/dcim/views.py
+++ b/netbox/dcim/views.py
@@ -355,7 +355,7 @@ def get_extra_context(self, request, instance):
 
         nonracked_devices = Device.objects.filter(
             site=instance,
-            position__isnull=True,
+            rack__isnull=True,
             parent_bay__isnull=True
         ).prefetch_related('device_type__manufacturer', 'parent_bay', 'device_role')
 
@@ -450,7 +450,7 @@ def get_extra_context(self, request, instance):
 
         nonracked_devices = Device.objects.filter(
             location=instance,
-            position__isnull=True,
+            rack__isnull=True,
             parent_bay__isnull=True
         ).prefetch_related('device_type__manufacturer', 'parent_bay', 'device_role')
 


Test patch: