Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes: #17498 - Avoid error in bulk import when non-unique identifying values are provided #17584

Closed

Conversation

bctiemann
Copy link
Contributor

Fixes: #17498

Extends _clean_fields to catch MultipleObjectsReturned exceptions on any field where an ad-hoc accessor is used (for example manufacturer.description in DeviceType) and multiple matching records are found.

With this change, a toast is displayed which surfaces the model that caused the exception. Because this is a non-field clean method, the field's specific metadata is not available, but the general message from the exception (which contains the model name) is reflected in the toast which should lead the user to a solution.

Note that other extraneous toasts appear as well as a side effect; this is not ideal, but this solution avoids the much greater issue of an opaque 500 error.

Screenshot 2024-09-23 at 8 05 13 PM

…oast with a useful message instead of a 500 error
@bctiemann bctiemann self-assigned this Sep 24, 2024
Copy link
Member

@jeremystretch jeremystretch left a comment

Choose a reason for hiding this comment

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

I think the root issue here is that the manufacturer field on DeviceTypeImportForm should be a CSVModelChoiceField, which properly handles the MultipleObjectsReturned exception. (The form's default_platform field should also be corrected.)

That said, I like your approach overriding the _clean_fields() method. We should explore whether this would obviate the need for our custom CSVModelChoiceField, but that should be handled as a separate housekeeping issue to ensure consistent implementation.

@bctiemann bctiemann closed this Sep 24, 2024
@bctiemann
Copy link
Contributor Author

Closing in favor of #17593

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bulk Import: Non-unique related field value leads to 500 error
2 participants