Invalid GraphQL output after deleting object used for object-type Custom Field #8077

Closed
opened 2025-12-29 20:32:03 +01:00 by adam · 11 comments
Owner

Originally created by @mikkelmk on GitHub (May 17, 2023).

NetBox version

v3.5.1

Python version

3.10

Steps to Reproduce

  1. Create object-type custom field with Interface as content type and Tag as object type
  2. Assign a tag to this custom field on an interface
  3. Delete the tag
  4. Querying the custom fields on the interface through GraphQL will still show the field as being set to the id of the deleted tag

Expected Behavior

GraphQL output like this:

{
  "data": {
    "interface": {
      "custom_fields": {
        "FooCustomField": null
      }
    }
  }
}

Observed Behavior

GraphQL output like this:

{
  "data": {
    "interface": {
      "custom_fields": {
        "FooCustomField": 42
      }
    }
  }
}

Note that the field will be null in both the Web interface and REST API - I believe that what happens is that the underlying custom_field_data on the interface is not cleared, but that the Web/API layer knows to nullify the invalid reference

Originally created by @mikkelmk on GitHub (May 17, 2023). ### NetBox version v3.5.1 ### Python version 3.10 ### Steps to Reproduce 1. Create object-type custom field with Interface as content type and Tag as object type 2. Assign a tag to this custom field on an interface 3. Delete the tag 4. Querying the custom fields on the interface through GraphQL will still show the field as being set to the id of the deleted tag ### Expected Behavior GraphQL output like this: ``` { "data": { "interface": { "custom_fields": { "FooCustomField": null } } } } ``` ### Observed Behavior GraphQL output like this: ``` { "data": { "interface": { "custom_fields": { "FooCustomField": 42 } } } } ``` **Note that the field will be null in both the Web interface and REST API** - I believe that what happens is that the underlying custom_field_data on the interface is not cleared, but that the Web/API layer knows to nullify the invalid reference
adam closed this issue 2025-12-29 20:32:03 +01:00
Author
Owner

@arthanson commented on GitHub (Aug 8, 2023):

@jeremystretch I don't think there is a way to do this performantly with the current design, since it is a content_type the reference to the object is stored in the json field, so there isn't a DB reference to signal the deletion of the referenced object. When deserializing from GraphQL it just returns the value of the json, to do this would need to query the referenced object to make sure it exists which would work for a single query but not a list (n+1 queries).

We could make a GFK mapping table for custom field object references (GFK -> GFK) That could clean up when the referenced object is deleted, but I don't think we would want to do that just for this.

@arthanson commented on GitHub (Aug 8, 2023): @jeremystretch I don't think there is a way to do this performantly with the current design, since it is a content_type the reference to the object is stored in the json field, so there isn't a DB reference to signal the deletion of the referenced object. When deserializing from GraphQL it just returns the value of the json, to do this would need to query the referenced object to make sure it exists which would work for a single query but not a list (n+1 queries). We could make a GFK mapping table for custom field object references (GFK -> GFK) That could clean up when the referenced object is deleted, but I don't think we would want to do that just for this.
Author
Owner

@jeremystretch commented on GitHub (Oct 2, 2023):

One idea I've had on the back burner is reimplementing the custom fields feature in NetBox to utilize discrete database fields (as opposed to monolithic JSON blobs) managed via dynamic schema migrations. I haven't gotten around to drafting an FR for that yet, but it occurs to me that such a change would resolve this bug as well.

@jeremystretch commented on GitHub (Oct 2, 2023): One idea I've had on the back burner is reimplementing the custom fields feature in NetBox to utilize discrete database fields (as opposed to monolithic JSON blobs) managed via dynamic schema migrations. I haven't gotten around to drafting an FR for that yet, but it occurs to me that such a change would resolve this bug as well.
Author
Owner

@github-actions[bot] commented on GitHub (Mar 15, 2024):

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.

@github-actions[bot] commented on GitHub (Mar 15, 2024): 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).
Author
Owner

@jeremystretch commented on GitHub (May 14, 2024):

@arthanson could you revisit this now that we've switched from Graphene to Strawberry in NetBox v4.0?

@jeremystretch commented on GitHub (May 14, 2024): @arthanson could you revisit this now that we've switched from Graphene to Strawberry in NetBox v4.0?
Author
Owner

@arthanson commented on GitHub (May 14, 2024):

This isn't blocked on GraphQL, it is blocked on Custom Field data being JSON blobs which would make this non-performant.

@arthanson commented on GitHub (May 14, 2024): This isn't blocked on GraphQL, it is blocked on Custom Field data being JSON blobs which would make this non-performant.
Author
Owner

@github-actions[bot] commented on GitHub (Aug 13, 2024):

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.

@github-actions[bot] commented on GitHub (Aug 13, 2024): 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).
Author
Owner

@jeremypng commented on GitHub (Jan 23, 2025):

Agreed that this is blocked on a Housekeeper feature or converting custom fields to discrete database records.

@jeremypng commented on GitHub (Jan 23, 2025): Agreed that this is blocked on a Housekeeper feature or converting custom fields to discrete database records.
Author
Owner

@jeremystretch commented on GitHub (Mar 14, 2025):

Is this still blocked? If so, let's identify the specific open issue(s) that are blocking it and call them out here for clarity.

@jeremystretch commented on GitHub (Mar 14, 2025): Is this still blocked? If so, let's identify the specific open issue(s) that are blocking it and call them out here for clarity.
Author
Owner

@arthanson commented on GitHub (May 29, 2025):

This is probably a high complexity issue as the custom fields are stored in JSON and trying to filter through this in a performant manner could be difficult.

@arthanson commented on GitHub (May 29, 2025): This is probably a high complexity issue as the custom fields are stored in JSON and trying to filter through this in a performant manner could be difficult.
Author
Owner

@github-actions[bot] commented on GitHub (Aug 28, 2025):

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.

@github-actions[bot] commented on GitHub (Aug 28, 2025): 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/main/CONTRIBUTING.md).
Author
Owner

@github-actions[bot] commented on GitHub (Oct 6, 2025):

This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.

@github-actions[bot] commented on GitHub (Oct 6, 2025): This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8077