Fixes #21320: Prevent Rack validation errors when site or optional fields are missing during import #449

Closed
opened 2026-04-05 16:33:16 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @pheus on 1/29/2026

Fixes: #21320

This PR prevents an uncaught exception during Rack direct import/validation when the site relation isn’t set (e.g. due to missing/incorrect CSV headers), which previously could raise RelatedObjectDoesNotExist.

Summary of changes

  • Update Rack validation to use the FK ID fields (site_id / location_id) instead of accessing related objects directly.
  • Avoid triggering related-object lookups during validation, ensuring we return normal, user-facing validation errors rather than a backend exception.
  • Aligns the validation logic with Django’s underlying foreign key fields and behavior when relations are unset.

Thanks again to @cpt-kernel-afk for the report and sample CSVs, and to @jnovinger for the review/suggestion to use FK IDs here.

*Originally created by @pheus on 1/29/2026* ### Fixes: #21320 This PR prevents an uncaught exception during Rack direct import/validation when the `site` relation isn’t set (e.g. due to missing/incorrect CSV headers), which previously could raise `RelatedObjectDoesNotExist`. #### Summary of changes - Update Rack validation to use the FK ID fields (`site_id` / `location_id`) instead of accessing related objects directly. - Avoid triggering related-object lookups during validation, ensuring we return normal, user-facing validation errors rather than a backend exception. - Aligns the validation logic with Django’s underlying foreign key fields and behavior when relations are unset. Thanks again to @cpt-kernel-afk for the report and sample CSVs, and to @jnovinger for the review/suggestion to use FK IDs here.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/netbox#449