On delete order was breaked with RESTRICT action #11908

Closed
opened 2025-12-29 21:51:24 +01:00 by adam · 3 comments
Owner

Originally created by @fanshan on GitHub (Dec 8, 2025).

Originally assigned to: @fanshan on GitHub.

NetBox Edition

NetBox Community

NetBox Version

v4.4.7

Python Version

3.12

Steps to Reproduce

Hello,

We create the Netbox Docker plugin and we face a problem on the delete cascade order.

Starting Netbox v4.4.7 in the plugin development context, if we create relations like this on a model Container:

host = models.ForeignKey(Host, on_delete=models.CASCADE, related_name="containers")
image = models.ForeignKey(
    Image, on_delete=models.RESTRICT, related_name="containers"
)

Then create a Host typed object, an Image typed object and a Container typed object linked to previous objects.

Try to delete the Host typed object.

An error IntegrityError at /plugins/docker/hosts/delete/ raise with the content:

null value in column "image_id" of relation "netbox_docker_plugin_container" violates not-null constraint
DETAIL:  Failing row contains (1, test, none, null, 1, null, 2025-12-08 16:04:32.912308+00, 2025-12-08 16:04:57.259281+00, {}, null, create, null, no, {}, null, {}).

Expected Behavior

The Host, Image and Container typed object are deleted.

Observed Behavior

An error IntegrityError at /plugins/docker/hosts/delete/ raise with the content:

null value in column "image_id" of relation "netbox_docker_plugin_container" violates not-null constraint
DETAIL:  Failing row contains (1, test, none, null, 1, null, 2025-12-08 16:04:32.912308+00, 2025-12-08 16:04:57.259281+00, {}, null, create, null, no, {}, null, {}).
Originally created by @fanshan on GitHub (Dec 8, 2025). Originally assigned to: @fanshan on GitHub. ### NetBox Edition NetBox Community ### NetBox Version v4.4.7 ### Python Version 3.12 ### Steps to Reproduce Hello, We create the [Netbox Docker plugin](https://github.com/SaaShup/netbox-docker-plugin) and we face a problem on the delete cascade order. Starting Netbox v4.4.7 in the plugin development context, if we create relations like this on a model `Container`: ```python host = models.ForeignKey(Host, on_delete=models.CASCADE, related_name="containers") image = models.ForeignKey( Image, on_delete=models.RESTRICT, related_name="containers" ) ``` Then create a Host typed object, an Image typed object and a Container typed object linked to previous objects. Try to delete the Host typed object. An error `IntegrityError at /plugins/docker/hosts/delete/` raise with the content: ``` null value in column "image_id" of relation "netbox_docker_plugin_container" violates not-null constraint DETAIL: Failing row contains (1, test, none, null, 1, null, 2025-12-08 16:04:32.912308+00, 2025-12-08 16:04:57.259281+00, {}, null, create, null, no, {}, null, {}). ``` ### Expected Behavior The Host, Image and Container typed object are deleted. ### Observed Behavior An error `IntegrityError at /plugins/docker/hosts/delete/` raise with the content: ``` null value in column "image_id" of relation "netbox_docker_plugin_container" violates not-null constraint DETAIL: Failing row contains (1, test, none, null, 1, null, 2025-12-08 16:04:32.912308+00, 2025-12-08 16:04:57.259281+00, {}, null, create, null, no, {}, null, {}). ```
adam added the type: bugstatus: acceptednetboxseverity: medium labels 2025-12-29 21:51:24 +01:00
adam closed this issue 2025-12-29 21:51:24 +01:00
Author
Owner

@arthanson commented on GitHub (Dec 9, 2025):

@fanshan I'm not understanding where NetBox is involved in this. This seems like a NetBox Docker issue, have you opened and issue there? If this was originally from NetBox Docker - can you please identify what it is in NetBox that is causing you an issue?

There is also a lot of information missing from here that we would need to reproduce this issue. Is the "Host" you create a foreign key to an ipam.lookup.Hosts? You Also say create an image typed object - Is this an image attachment?

@arthanson commented on GitHub (Dec 9, 2025): @fanshan I'm not understanding where NetBox is involved in this. This seems like a NetBox Docker issue, have you opened and issue there? If this was originally from NetBox Docker - can you please identify what it is in NetBox that is causing you an issue? There is also a lot of information missing from here that we would need to reproduce this issue. Is the "Host" you create a foreign key to an ipam.lookup.Hosts? You Also say create an image typed object - Is this an image attachment?
Author
Owner

@fanshan commented on GitHub (Dec 10, 2025):

Hello @arthanson,

I am a maintainers of Netbox Docker Plugin and since the Netbox release 4.4.6 (especially this fix https://github.com/netbox-community/netbox/issues/20699) we face the issue I described before.

You can see our Container models here https://github.com/SaaShup/netbox-docker-plugin/blob/main/netbox_docker_plugin/models/container.py#L115

A Host is an entity that represents a Docker Agent connecting with the Netbox Docker Plugin. On each Host we add, we can create Containers based on Docker Images.

Before the Netbox version 4.4.6, we can delete a Host and all entities in relation with this Host will be deleted (meaning all Containers and Images). But since the Netbox version 4.4.6 when we delete a Host, an error raise like discribed on the issue above.

I provide the PR https://github.com/netbox-community/netbox/pull/20949 that solves the issue but I don't know if this will fit with all Netbox core models.

We are always follow the Netbox plugin development principle and Netbox version so If we have to change something in our code base we will do it. But if we don't solve this issue, we are stuck with the Netbox version 4.4.5.

Thank you for your help.

@fanshan commented on GitHub (Dec 10, 2025): Hello @arthanson, I am a maintainers of Netbox Docker Plugin and since the Netbox release 4.4.6 (especially this fix https://github.com/netbox-community/netbox/issues/20699) we face the issue I described before. You can see our Container models here https://github.com/SaaShup/netbox-docker-plugin/blob/main/netbox_docker_plugin/models/container.py#L115 A Host is an entity that represents a Docker Agent connecting with the Netbox Docker Plugin. On each Host we add, we can create Containers based on Docker Images. Before the Netbox version 4.4.6, we can delete a Host and all entities in relation with this Host will be deleted (meaning all Containers and Images). But since the Netbox version 4.4.6 when we delete a Host, an error raise like discribed on the issue above. I provide the PR https://github.com/netbox-community/netbox/pull/20949 that solves the issue but I don't know if this will fit with all Netbox core models. We are always follow the Netbox plugin development principle and Netbox version so If we have to change something in our code base we will do it. But if we don't solve this issue, we are stuck with the Netbox version 4.4.5. Thank you for your help.
Author
Owner

@lvenier commented on GitHub (Dec 16, 2025):

@arthanson thanks for having looked at it. if there is anything we can do to help please let us know.

@lvenier commented on GitHub (Dec 16, 2025): @arthanson thanks for having looked at it. if there is anything we can do to help please let us know.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11908