Better BULK operation error response, providing offending object -> error correlation #11463

Open
opened 2025-12-29 21:45:34 +01:00 by adam · 2 comments
Owner

Originally created by @jseifeddine on GitHub (Aug 8, 2025).

NetBox version

v4.3.4

Feature type

New functionality

Proposed functionality

  • For bulk list-endpoint updates (e.g., PATCH to .../api/dcim/interfaces/), return a structured error payload that correlates each submitted object with its validation outcome.
  • Return per-object validation errors so clients can identify and retry only the failing items.
  • Response shape (example) when any item fails:
    {
      "detail": "One or more objects failed validation",
      "results": [
        { "id": 1, "status": "ok" },
        {
          "id": 2,
          "status": "error",
          "errors": {
            "description": ["Ensure this field has no more than 200 characters."]
          }
        },
        { "id": 3, "status": "ok" }
      ],
      "succeeded": [1, 3],
      "failed": [2]
    }
    
  • Success case (all pass) remains unchanged (200 with updated objects).
  • Error status remains 400 to preserve backward compatibility; the new body adds per-object detail.
  • Optional enhancement (non-breaking, future-friendly): support an HTTP 207 Multi-Status alternative or a query flag (e.g., ?verbose_errors=true) to opt into the detailed error shape.

Use case

  • When performing large bulk updates (e.g., 100–1000 objects), a single invalid item currently returns an aggregate field error without indicating which object(s) failed (e.g., {"description": ["Ensure this field has no more than 200 characters."]}).
  • Clients must then bisect or iterate requests to isolate the bad object(s), incurring extra API calls and complexity.
  • With per-object error correlation, clients can:
    • Immediately identify the offending ID(s)
    • Drop or correct invalid items
    • Retry only the problematic subset
  • This significantly reduces operational time and complexity for workflows that rely on bulk operations (inventory sync, onboarding, mass edits).

Database changes

  • None. This is an API response enhancement in the bulk update path (e.g., BulkUpdateModelMixin) and serializers; no model or schema changes required.

External dependencies

  • None
Originally created by @jseifeddine on GitHub (Aug 8, 2025). ### NetBox version v4.3.4 ### Feature type New functionality ### Proposed functionality - For bulk list-endpoint updates (e.g., PATCH to `.../api/dcim/interfaces/`), return a structured error payload that correlates each submitted object with its validation outcome. - Return per-object validation errors so clients can identify and retry only the failing items. - Response shape (example) when any item fails: ```json { "detail": "One or more objects failed validation", "results": [ { "id": 1, "status": "ok" }, { "id": 2, "status": "error", "errors": { "description": ["Ensure this field has no more than 200 characters."] } }, { "id": 3, "status": "ok" } ], "succeeded": [1, 3], "failed": [2] } ``` - Success case (all pass) remains unchanged (200 with updated objects). - Error status remains 400 to preserve backward compatibility; the new body adds per-object detail. - Optional enhancement (non-breaking, future-friendly): support an HTTP 207 Multi-Status alternative or a query flag (e.g., `?verbose_errors=true`) to opt into the detailed error shape. ### Use case - When performing large bulk updates (e.g., 100–1000 objects), a single invalid item currently returns an aggregate field error without indicating which object(s) failed (e.g., `{"description": ["Ensure this field has no more than 200 characters."]}`). - Clients must then bisect or iterate requests to isolate the bad object(s), incurring extra API calls and complexity. - With per-object error correlation, clients can: - Immediately identify the offending ID(s) - Drop or correct invalid items - Retry only the problematic subset - This significantly reduces operational time and complexity for workflows that rely on bulk operations (inventory sync, onboarding, mass edits). ### Database changes - None. This is an API response enhancement in the bulk update path (e.g., `BulkUpdateModelMixin`) and serializers; no model or schema changes required. ### External dependencies - None
Author
Owner

@jseifeddine commented on GitHub (Aug 12, 2025):

Same issue with deletes

Test with deleting many sites with dependent objects.

DEBUG : Bulk deleting 250 sites...
ERROR : Bulk delete failed for 250 sites: The request failed with code 409 Conflict: {'detail': 'Unable to delete object. 1 dependent objects were found: DummyDevice (16483)'}

The whole batch fails and returns error referencing only one object.

@jseifeddine commented on GitHub (Aug 12, 2025): Same issue with deletes Test with deleting many sites with dependent objects. `DEBUG : Bulk deleting 250 sites...` `ERROR : Bulk delete failed for 250 sites: The request failed with code 409 Conflict: {'detail': 'Unable to delete object. 1 dependent objects were found: DummyDevice (16483)'}` The whole batch fails and returns error referencing only one object.
Author
Owner

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

One point to consider: Objects being created in the request won't have a primary key assigned, so an alternative mechanism is needed to correlate error messages to those (likely the index of the object in the request data).

@jeremystretch commented on GitHub (Aug 14, 2025): One point to consider: Objects being created in the request won't have a primary key assigned, so an alternative mechanism is needed to correlate error messages to those (likely the index of the object in the request data).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11463