Skip to content

M2m validation errors#174

Open
MLewiDev wants to merge 6 commits intomasterfrom
m2m-validation-errors
Open

M2m validation errors#174
MLewiDev wants to merge 6 commits intomasterfrom
m2m-validation-errors

Conversation

@MLewiDev
Copy link
Copy Markdown

No description provided.

@MLewiDev MLewiDev requested a review from stefanmajoor June 29, 2021 07:05
@MLewiDev MLewiDev marked this pull request as draft June 29, 2021 07:06
@MLewiDev MLewiDev marked this pull request as ready for review July 26, 2021 08:43
Comment thread binder/views.py Outdated
Comment thread binder/views.py
Comment on lines +2006 to +2009
except BinderFieldTypeError:
if not validation_errors:
raise

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So I see 2 issues with this approach:

  • This now works for all BinderFieldTypeErrors, not just the ones that are caused by the save of another model not working. In the other cases a BinderFieldTypeError should be more important than a validation error.
  • If both the related model and the main model have validation errors this will now ignore the validation errors on the main model.

I would suggest to instead pass an extra argument to _store that provides which models have failed to save and then prevent the BinderFieldTypeError from being raised when the value refers to one of these models.

Copy link
Copy Markdown
Author

@MLewiDev MLewiDev Jan 31, 2022

Choose a reason for hiding this comment

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

Managed to create test for the second bullet, but I have a problem in generating a test for the first bullet point related to BinderFieldTypeError. Can you give some tips?

After writing failing tests i will start with refactor and try to use _store.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So a BinderFieldTypeError should occur when the value that you are trying to save does not match the type of the field, so for example trying to save a string into an integer field. Do note that django does try to 'fix' values. So for example the other way around (an integer to a string field) it would just turn the integer into a string.

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.

2 participants