Missing change log entries for updated many-to-many fields as part of deletes #8760

Closed
opened 2025-12-29 20:40:52 +01:00 by adam · 4 comments
Owner

Originally created by @fabi125 on GitHub (Oct 19, 2023).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.6.4

Python version

3.8

Steps to Reproduce

  1. Create a couple of device roles and a config context that is assigned to those two roles:
{
    "id": 1,
    "url": "https://demo.netbox.dev/api/extras/config-contexts/1/",
    "display": "Test Context",
    "name": "Test Context",
    "weight": 1000,
    "description": "",
    "is_active": true,
    "regions": [],
    "site_groups": [],
    "sites": [],
    "locations": [],
    "device_types": [],
    "roles": [
        {
            "id": 13,
            "url": "https://demo.netbox.dev/api/dcim/device-roles/13/",
            "display": "Test Role",
            "name": "Test Role",
            "slug": "test-role"
        },
        {
            "id": 14,
            "url": "https://demo.netbox.dev/api/dcim/device-roles/14/",
            "display": "Test Role 2",
            "name": "Test Role 2",
            "slug": "test-role-2"
        }
    ],
    "platforms": [],
    "cluster_types": [],
    "cluster_groups": [],
    "clusters": [],
    "tenant_groups": [],
    "tenants": [],
    "tags": [],
    "data_source": null,
    "data_path": "",
    "data_file": null,
    "data_synced": null,
    "data": {
        "foo": 123
    },
    "created": "2023-10-18T22:07:46.872083Z",
    "last_updated": "2023-10-18T22:07:46.872120Z"
}
  1. Delete one of the roles

Expected Behavior

This should result in two change log entries: one for the device role deletion and one for the update to the config context.

Observed Behavior

Only a single change log entry is created:

GET /api/extras/object-changes/?request_id=8f69edb2-918f-40da-ac13-2fd1b8d5a3e6

{
    "count": 1,
    "next": null,
    "previous": null,
    "results": [
        {
            "id": 5179,
            "url": "https://demo.netbox.dev/api/extras/object-changes/5179/",
            "display": "dcim | device role Test Role deleted by admin",
            "time": "2023-10-18T22:08:46.787241Z",
            "user": {
                "id": 54,
                "url": "https://demo.netbox.dev/api/users/users/54/",
                "display": "admin",
                "username": "admin"
            },
            "user_name": "admin",
            "request_id": "8f69edb2-918f-40da-ac13-2fd1b8d5a3e6",
            "action": {
                "value": "delete",
                "label": "Deleted"
            },
            "changed_object_type": "dcim.devicerole",
            "changed_object_id": 13,
            "changed_object": null,
            "prechange_data": {
                "name": "Test Role",
                "slug": "test-role",
                "tags": [],
                "color": "9e9e9e",
                "created": "2023-10-18T22:07:13.945Z",
                "vm_role": true,
                "description": "",
                "last_updated": "2023-10-18T22:07:13.945Z",
                "custom_fields": {},
                "config_template": null
            },
            "postchange_data": null
        }
    ]
}

But the config context is updated:

{
    "id": 1,
    "url": "https://demo.netbox.dev/api/extras/config-contexts/1/",
    "display": "Test Context",
    "name": "Test Context",
    "weight": 1000,
    "description": "",
    "is_active": true,
    "regions": [],
    "site_groups": [],
    "sites": [],
    "locations": [],
    "device_types": [],
    "roles": [
        {
            "id": 14,
            "url": "https://demo.netbox.dev/api/dcim/device-roles/14/",
            "display": "Test Role 2",
            "name": "Test Role 2",
            "slug": "test-role-2"
        }
    ],
    "platforms": [],
    "cluster_types": [],
    "cluster_groups": [],
    "clusters": [],
    "tenant_groups": [],
    "tenants": [],
    "tags": [],
    "data_source": null,
    "data_path": "",
    "data_file": null,
    "data_synced": null,
    "data": {
        "foo": 123
    },
    "created": "2023-10-18T22:07:46.872083Z",
    "last_updated": "2023-10-18T22:07:46.872120Z"
}

Note: I believe this affects all models that use ManyToManyField relations.

Originally created by @fabi125 on GitHub (Oct 19, 2023). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.6.4 ### Python version 3.8 ### Steps to Reproduce 1. Create a couple of device roles and a config context that is assigned to those two roles: ``` { "id": 1, "url": "https://demo.netbox.dev/api/extras/config-contexts/1/", "display": "Test Context", "name": "Test Context", "weight": 1000, "description": "", "is_active": true, "regions": [], "site_groups": [], "sites": [], "locations": [], "device_types": [], "roles": [ { "id": 13, "url": "https://demo.netbox.dev/api/dcim/device-roles/13/", "display": "Test Role", "name": "Test Role", "slug": "test-role" }, { "id": 14, "url": "https://demo.netbox.dev/api/dcim/device-roles/14/", "display": "Test Role 2", "name": "Test Role 2", "slug": "test-role-2" } ], "platforms": [], "cluster_types": [], "cluster_groups": [], "clusters": [], "tenant_groups": [], "tenants": [], "tags": [], "data_source": null, "data_path": "", "data_file": null, "data_synced": null, "data": { "foo": 123 }, "created": "2023-10-18T22:07:46.872083Z", "last_updated": "2023-10-18T22:07:46.872120Z" } ``` 2. Delete one of the roles ### Expected Behavior This should result in two change log entries: one for the device role deletion and one for the update to the config context. ### Observed Behavior Only a single change log entry is created: `GET /api/extras/object-changes/?request_id=8f69edb2-918f-40da-ac13-2fd1b8d5a3e6` ``` { "count": 1, "next": null, "previous": null, "results": [ { "id": 5179, "url": "https://demo.netbox.dev/api/extras/object-changes/5179/", "display": "dcim | device role Test Role deleted by admin", "time": "2023-10-18T22:08:46.787241Z", "user": { "id": 54, "url": "https://demo.netbox.dev/api/users/users/54/", "display": "admin", "username": "admin" }, "user_name": "admin", "request_id": "8f69edb2-918f-40da-ac13-2fd1b8d5a3e6", "action": { "value": "delete", "label": "Deleted" }, "changed_object_type": "dcim.devicerole", "changed_object_id": 13, "changed_object": null, "prechange_data": { "name": "Test Role", "slug": "test-role", "tags": [], "color": "9e9e9e", "created": "2023-10-18T22:07:13.945Z", "vm_role": true, "description": "", "last_updated": "2023-10-18T22:07:13.945Z", "custom_fields": {}, "config_template": null }, "postchange_data": null } ] } ``` But the config context is updated: ``` { "id": 1, "url": "https://demo.netbox.dev/api/extras/config-contexts/1/", "display": "Test Context", "name": "Test Context", "weight": 1000, "description": "", "is_active": true, "regions": [], "site_groups": [], "sites": [], "locations": [], "device_types": [], "roles": [ { "id": 14, "url": "https://demo.netbox.dev/api/dcim/device-roles/14/", "display": "Test Role 2", "name": "Test Role 2", "slug": "test-role-2" } ], "platforms": [], "cluster_types": [], "cluster_groups": [], "clusters": [], "tenant_groups": [], "tenants": [], "tags": [], "data_source": null, "data_path": "", "data_file": null, "data_synced": null, "data": { "foo": 123 }, "created": "2023-10-18T22:07:46.872083Z", "last_updated": "2023-10-18T22:07:46.872120Z" } ``` Note: I believe this affects all models that use `ManyToManyField` relations.
adam added the type: bugstatus: acceptedseverity: medium labels 2025-12-29 20:40:52 +01:00
adam closed this issue 2025-12-29 20:40:52 +01:00
Author
Owner

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

I believe this would be addressed by FR #14059.

@jeremystretch commented on GitHub (Oct 19, 2023): I believe this would be addressed by FR #14059.
Author
Owner

@fabi125 commented on GitHub (Oct 19, 2023):

I believe this would be addressed by FR #14059.

Ah yes! I tried to search for open issues, but couldn't find anything. Great timing how you just opened it 2 days ago :)

@fabi125 commented on GitHub (Oct 19, 2023): > I believe this would be addressed by FR #14059. Ah yes! I tried to search for open issues, but couldn't find anything. Great timing how you just opened it 2 days ago :)
Author
Owner

@fabi125 commented on GitHub (Oct 20, 2023):

Note: I also found this 12 year old Django bug that seems related: https://code.djangoproject.com/ticket/17688
So the easiest way for NetBox to fix this, is probably #14059.

@fabi125 commented on GitHub (Oct 20, 2023): Note: I also found this 12 year old Django bug that seems related: https://code.djangoproject.com/ticket/17688 So the easiest way for NetBox to fix this, is probably #14059.
Author
Owner

@jeremystretch commented on GitHub (Dec 27, 2023):

It may be some time before we can tackle #14059 (assuming it's even feasible), so let's see if we can come with a fix in the interim.

@jeremystretch commented on GitHub (Dec 27, 2023): It may be some time before we can tackle #14059 (assuming it's even feasible), so let's see if we can come with a fix in the interim.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8760