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

Validation when using ModelResource #176

Closed
sergei-maertens opened this issue Nov 12, 2014 · 9 comments
Closed

Validation when using ModelResource #176

sergei-maertens opened this issue Nov 12, 2014 · 9 comments

Comments

@sergei-maertens
Copy link

Is anybody working on validation for resources generated by the modelresource_factory?

For instance, a Django CharField that has choices as keyword argument should be validated when importing. The value in the import file should match one of the possible values.

Another example is again with CharFields: make sure that max_length is respected and if the provided value is too long, trim it with django.utils.text.Truncator.

If this sounds reasonable, I'm definitely willing to put some time in it to add those validation rules and make a pull request. Right now for a project I'm overriding quite a bit of stuff to make this possible.

@bmihelac
Copy link
Member

Hi @sergei-maertens!

For instance, a Django CharField that has choices as keyword argument should be validated when importing. The value in the import file should match one of the possible values.

In this case django will raise an exception and this exception will be presented to user together with line number. I am aware that as much as I wanted this errors to be descriptive with including stack trace they are sometimes confusing. I wish we have better error reporting and I am open for ideas.

Another example is again with CharFields: make sure that max_length is respected and if the provided value is too long, trim it with django.utils.text.Truncator.

This is not validation, but some processing of data, right?

@sergei-maertens
Copy link
Author

I think that user-directed validation errors should be displayed below the
field, similar to form validation, instead of providing a traceback. Admin
users are not necessarily developers, so I'd opt for a more human readable
error here.

The max length example leads to a DatabaseIntegriyError if untreated, and
the same goes for empty columns in case of BooleanField if it's not a
NullBooleanField.

Those things should be caught on the widget or field by introspecting the
related Django model field in my opinion.

@bmihelac
Copy link
Member

I agree, this would be nice feature.

@ses4j
Copy link

ses4j commented Apr 3, 2017

Did anything ever come of this?

@sergei-maertens
Copy link
Author

No, not yet

@dz0
Copy link

dz0 commented Aug 8, 2018

maybe just call instance.full_clean() in before_save_instance(..)

@ababic
Copy link
Contributor

ababic commented Nov 2, 2018

Hi @bmihelac.

I've got a version of this working locally, which I think is 'pretty okay'. However, I'm sure you'll have your own ideas about a few things (as will always be the case with changes of this size). Is this something you'd rather solve yourself, or would you be happy for me to submit a PR, and we can bash things into shape together?

@bmihelac
Copy link
Member

bmihelac commented Nov 2, 2018

Hi @ababic, it would be great if you can submit a PR for this. Having better validation/error messages would be excellent.

@bmihelac
Copy link
Member

bmihelac commented Dec 4, 2018

Fixed with bd5ce92.

@bmihelac bmihelac closed this as completed Dec 4, 2018
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

No branches or pull requests

5 participants