Re: Django Rest Framework Validation Order Issue

2020-07-01 Thread Brent O'Connor
Hi Özgür, I'm not sure if you saw it or not but I did come up with a solution in another branch (https://github.com/epicserve/drf-validation-issue/blob/fix-validation/pizzas/serializers.py) and I did end up overriding *run_validation* and *to_internal_value*. If I can find time, I think I'll

Re: Django Rest Framework Validation Order Issue

2020-07-01 Thread Özgür Akçalı
I think you also need to override *run_validators *method in your example project for it to work as you expect, just like you did for *to_internal_value. *If a validation error is raised fom run_validators method, *validate *method is not called, so you can not aggregate any possible errors rais

Re: Django Rest Framework Validation Order Issue

2020-07-01 Thread Özgür Akçalı
Though you can not achieve what you want by just overriding *validate, *and not overriding *run_validation*. This would be a major change in DRF though, as with the current behavior, when you write your *validate *method, you can assume other validations passed, so I imagine changing this beha

Re: Django Rest Framework Validation Order Issue

2020-06-30 Thread Brent O'Connor
I guess my point is that I don't feel like I should have to override anything and this should be DRF's default behavior. 🙂 Thank you for pointing out that `validation` should be the method that should be used. On Tue, Jun 30, 2020, 5:42 PM Carl Nobile wrote: > Brent, overriding the 'to_internal_

Re: Django Rest Framework Validation Order Issue

2020-06-30 Thread Carl Nobile
Brent, overriding the 'to_internal_value' method is normal and encouraged, however, the 'run_validation' shouldn't generally be overridden, what you can override is the 'validate' method which is called by 'run_validation'. ~Carl On Tue, Jun 30, 2020 at 5:51 PM Brent O'Connor wrote: > For anyone

Re: Django Rest Framework Validation Order Issue

2020-06-30 Thread Brent O'Connor
For anyone that might come across this thread, I went ahead and created an issue for this on Github. On Friday, June 26, 2020 at 5:08:03 PM UTC-5, Brent O'Connor wrote: > > I created an example project >

Re: Django Rest Framework Validation Order Issue

2020-06-30 Thread Brent O'Connor
Carl, I created another branch on my example project that solves this issue by overriding two DRF methods (to_internal_value and run_validation). I'm probably going to create an issue in DRF that sugg

Re: Django Rest Framework Validation Order Issue

2020-06-29 Thread Brent O'Connor
I understand that you can go about solving it this way, but it seems like a lot of extra work when it just works the way you would expect on a Django ModelForm. I'm guessing this isn't possible for it to "just work", so I might end up making an issue in the DRF project. On Saturday, June 27, 20

Re: Django Rest Framework Validation Order Issue

2020-06-27 Thread Carl Nobile
Then write your custom validation as a field validator and put them all in the list in the order you want them to fire off in or you could include the field validator checks into your custom validation method. The problem is that DRF can only implement what the common cases are, not all the edge ca

Re: Django Rest Framework Validation Order Issue

2020-06-27 Thread Brent O'Connor
Unfortunately, that doesn't really solve the issue because you want field-level validation to run because you want to make sure that valid numbers, etc. are being sent to the API. On Sat, Jun 27, 2020 at 12:25 PM Carl Nobile wrote: > It is possible to turn off the built infield errors. The empty

Re: Django Rest Framework Validation Order Issue

2020-06-27 Thread Carl Nobile
It is possible to turn off the built infield errors. The empty list essentially turns off al field validation. If there are multiple and you don't want all turned off you would need to specify them yourself. Class SomeSeializer(...): class Meta: extra_kwargs = { 'field_name

Django Rest Framework Validation Order Issue

2020-06-26 Thread Brent O'Connor
I created an example project to illustrate this issue, but basically if you have custom validation logic on a serializer and the data has a field that isn't valid, then the errors raised are only the field level errors and not the custom valid