Skip to content

Conversation

@pheus
Copy link
Contributor

@pheus pheus commented Jan 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.

@pheus pheus requested review from a team and jnovinger and removed request for a team January 29, 2026 14:35
Copy link
Member

@jnovinger jnovinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some thoughts on how you're checking those values safely.

Use `site_id` and `location_id` for validation to avoid triggering
related object lookups during import/validation. This aligns the logic
with the underlying foreign key fields and prevents
`RelatedObjectDoesNotExist` errors when relations are unset.

Fixes: #21320
@pheus pheus force-pushed the 21320-rack-direct-import-rack-has-no-site branch from 8860f2c to 75106e1 Compare February 2, 2026 20:06
@pheus pheus requested a review from jnovinger February 2, 2026 20:10
@jnovinger jnovinger merged commit ee6cbdc into main Feb 3, 2026
10 of 22 checks passed
@jnovinger jnovinger deleted the 21320-rack-direct-import-rack-has-no-site branch February 3, 2026 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rack Direct Import - "Rack has no site."

3 participants