Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango ModelForm not calling clean
    primarykey
    data
    text
    <p>I am performing a basic Django ModelForm create/validate/save operation. My custom clean methods are not being called when is_valid() is being called when running the code under the Eclipse debugger and I set a breakpoint after the form creation and the call to is_valid().</p> <p>I have traced through the Django base code numerous times and it appears that the error dictionary on the ModelForm class is never set to None, which triggers the validation. I suspect that this is due to an interaction with the debugger accessing the _errors attribute of the ModelForm to display in the variables pane.</p> <p>When I remove all breakpoints and let the code flow naturally, I can prove that the custom clean code is running by issuing print statements.</p> <p>Is this a flaw in the Django ModelForm design, an Eclipse problem or am I barking up the wrong tree?</p> <p>models.py</p> <pre><code>from django.db import models class TestModel1(models.Model): field1 = models.CharField(max_length=45) field2 = models.IntegerField(default=2) field3 = models.CharField(max_length=45, null=True, blank=True) </code></pre> <p>forms.py</p> <pre><code>from order.models import TestModel1 from django.forms import ModelForm class OrderTestForm(ModelForm): def clean_field1(self): return self.cleaned_data['field1'] def clean_field2(self): return self.cleaned_data['field2'] class Meta: model = TestModel1 </code></pre> <p>My test harness:</p> <pre><code>from forms import OrderTestForm row = {'field1': 'test value', 'field2': '4', } ff = OrderTestForm(row) #ff.full_clean() if ff.is_valid(): ff.save() else: print ff.errors </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload