[PR #20538] [MERGED] Fixes #20466: Correct handling of assigned filter logic #15959

Closed
opened 2025-12-30 00:25:01 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/20538
Author: @pheus
Created: 10/9/2025
Status: Merged
Merged: 10/19/2025
Merged by: @jnovinger

Base: mainHead: 20466-fix-assigned-graphql-ipaddressfilter


📝 Commits (1)

  • 5bdc4fa fix(graphql): Correct handling of assigned filter logic

📊 Changes

1 file changed (+1 additions, -1 deletions)

View changed files

📝 netbox/ipam/graphql/filters.py (+1 -1)

📄 Description

Fixes: #20466

Summary

  • Correct the custom GraphQL filter IPAddressFilter.assigned to use the nested relation prefix supplied by Strawberry‑Django.
  • Prior behavior built a non‑prefixed Q, so when used under another filter (e.g., Device → primary_ip4), Django attempted to resolve assigned_object_id on the outer model and failed.
  • New behavior dynamically qualifies the lookup with prefix, ensuring the condition targets the nested IPAddress.

Change

@strawberry_django.filter_field()
def assigned(self, value: bool, prefix) -> Q:
-    return Q(assigned_object_id__isnull=(not value))
+    return Q(**{f"{prefix}assigned_object_id__isnull": not value})

Why

Nested GraphQL queries like the example below errored due to the missing prefix; with this change they work as intended.

query {
  device_list(filters: { primary_ip4: { assigned: true } }) {
    id
    name
    primary_ip4 { address }
  }
}

Follow‑up

  • Propose a small audit for other @strawberry_django.filter_field methods that construct raw Q(...) lookups without applying prefix.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/20538 **Author:** [@pheus](https://github.com/pheus) **Created:** 10/9/2025 **Status:** ✅ Merged **Merged:** 10/19/2025 **Merged by:** [@jnovinger](https://github.com/jnovinger) **Base:** `main` ← **Head:** `20466-fix-assigned-graphql-ipaddressfilter` --- ### 📝 Commits (1) - [`5bdc4fa`](https://github.com/netbox-community/netbox/commit/5bdc4fa87bf9cc2d664300f483e4a3d16f5691e1) fix(graphql): Correct handling of `assigned` filter logic ### 📊 Changes **1 file changed** (+1 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `netbox/ipam/graphql/filters.py` (+1 -1) </details> ### 📄 Description ### Fixes: #20466 <!-- Please include a summary of the proposed changes below. --> #### Summary - Correct the custom GraphQL filter `IPAddressFilter.assigned` to use the nested relation `prefix` supplied by Strawberry‑Django. - Prior behavior built a non‑prefixed `Q`, so when used under another filter (e.g., `Device → primary_ip4`), Django attempted to resolve `assigned_object_id` on the outer model and failed. - New behavior dynamically qualifies the lookup with `prefix`, ensuring the condition targets the nested `IPAddress`. #### Change ```diff @strawberry_django.filter_field() def assigned(self, value: bool, prefix) -> Q: - return Q(assigned_object_id__isnull=(not value)) + return Q(**{f"{prefix}assigned_object_id__isnull": not value}) ``` #### Why Nested GraphQL queries like the example below errored due to the missing prefix; with this change they work as intended. ```graphql query { device_list(filters: { primary_ip4: { assigned: true } }) { id name primary_ip4 { address } } } ``` #### Follow‑up - Propose a small audit for other `@strawberry_django.filter_field` methods that construct raw `Q(...)` lookups without applying `prefix`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-30 00:25:01 +01:00
adam closed this issue 2025-12-30 00:25:01 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#15959