[PR #19006] [MERGED] Fixes #18991: AttributeError: NoneType object has not attribute model #15496

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

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/19006
Author: @jnovinger
Created: 3/25/2025
Status: Merged
Merged: 3/26/2025
Merged by: @arthanson

Base: mainHead: 18991-front-rear-port-paths-broken-api


📝 Commits (1)

  • 636148f Fixes #18991: AttributeError: NoneType object has not attribute model

📊 Changes

2 files changed (+41 additions, -3 deletions)

View changed files

📝 netbox/dcim/tests/test_api.py (+39 -1)
📝 netbox/utilities/fields.py (+2 -2)

📄 Description

Fixes: #18991

GenericArrayForeignKey, which was added in #18826, advertised itself as a many_to_many relation, which is seemingly somewhat inaccurate and triggered DRF's introspection of many_to_many relations which looks for a remote_field.model property chain on the relation. Since that doesn't exist, DRF threw an AttributeError resulting in a 500 error.

This changes GenericArrayForeignKey to advertise itself to DRF as a one_to_many relation, which is more accurate, and does not trigger the property access in DRF that was causing the problem.

This also adds a regression test for both FrontPort and RearPort "path" API views.


🔄 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/19006 **Author:** [@jnovinger](https://github.com/jnovinger) **Created:** 3/25/2025 **Status:** ✅ Merged **Merged:** 3/26/2025 **Merged by:** [@arthanson](https://github.com/arthanson) **Base:** `main` ← **Head:** `18991-front-rear-port-paths-broken-api` --- ### 📝 Commits (1) - [`636148f`](https://github.com/netbox-community/netbox/commit/636148f9654b82f7e664645f3e781a4591a22132) Fixes #18991: AttributeError: NoneType object has not attribute model ### 📊 Changes **2 files changed** (+41 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `netbox/dcim/tests/test_api.py` (+39 -1) 📝 `netbox/utilities/fields.py` (+2 -2) </details> ### 📄 Description <!-- Thank you for your interest in contributing to NetBox! Please note that our contribution policy requires that a feature request or bug report be approved and assigned prior to opening a pull request. This helps avoid waste time and effort on a proposed change that we might not be able to accept. IF YOUR PULL REQUEST DOES NOT REFERENCE AN ISSUE WHICH HAS BEEN ASSIGNED TO YOU, IT WILL BE CLOSED AUTOMATICALLY. Please specify your assigned issue number on the line below. --> ### Fixes: #18991 `GenericArrayForeignKey`, which was added in #18826, advertised itself as a many_to_many relation, which is seemingly somewhat inaccurate and [triggered DRF's introspection of many_to_many relations](https://github.com/encode/django-rest-framework/blob/73cbb9cd4acd36f859d9f656b8f134c9d2a754f3/rest_framework/utils/model_meta.py#L88-L101) which looks for a `remote_field.model` property chain on the relation. Since that doesn't exist, DRF threw an AttributeError resulting in a 500 error. This changes `GenericArrayForeignKey` to advertise itself to DRF as a one_to_many relation, which is more accurate, and does not trigger the property access in DRF that was causing the problem. This also adds a regression test for both FrontPort and RearPort "path" API views. <!-- Please include a summary of the proposed changes below. --> --- <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:22:18 +01:00
adam closed this issue 2025-12-30 00:22:18 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#15496