You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Deleting a multi-object field leaves its through model registered in other workers; later deletes of related objects fail with 'relation … does not exist' #840
With NetBox running more than one worker process (process A plays one worker, process B another):
Create a Custom Object Type with a (non-polymorphic) multi-object field devices pointing at dcim.device, and a device.
In process A, access the type so its model and the field's through model (Through_custom_objects_<id>_devices) are registered in A's app registry.
In process B, delete the devices field.
In process A, delete the device.
Expected Behavior
The device is deleted.
Observed Behavior
Expected, from reading the code (not yet reproduced across two processes):
ProgrammingError: relation "custom_objects_<id>_devices" does not exist
Once a worker is in this state, every delete of an object the dropped field pointed at fails in that worker until NetBox is restarted.
Suspected Cause
This is #755 for fields instead of types. CustomObjectTypeField.delete() drops the through table and unregisters the through model, but only in the process that handles the delete. Other workers see the type's changed cache_timestamp and regenerate its model on the next lookup, but regeneration doesn't remove through models whose field no longer exists. The stale through model stays registered, so it stays in the target model's _meta.related_objects, and deleting a target object makes the delete collector (and core's handle_deleted_object) query the dropped table.
The same applies to polymorphic multi-object fields, whose through model is related to every allowed target type.
Proposed Fix
Extend the mechanism from #756 (stale_models.py) to fields: once a multi-object field's delete commits, mark it as deleted in the shared cache and change the token. On eviction, each worker also unregisters the through models of marked fields, if the field no longer exists.
Activity