This is a real pain. I have this problem twice, and I have not yet found a good solution.
This is an example of safe debugging when overriding the __init__ form method.
class MyForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(MyForm, self).__init__(*args, **kwargs)
If you want to debug the base classes of classes, then patch the Django code in the same way.
You can leave or remove this additional code after debugging - this is not significant. But it is better to leave this business in the future.
So what is really going on here?
(bugreport on the Django project website: https://code.djangoproject.com/ticket/24710 )
The problem seems to be that the gango BaseForm.errors getter property (which is actually a method with @property decorator) does too much. It calls the full_clean() method, which changes the value of the _errors property, so that the errors getter does not do the same job again on repeated calls.
class BaseForm(object): @property def errors(self): if self._errors is None: self.full_clean() return self._errors def full_clean(self): self._errors = ErrorDict() ...
Of course, the PyCharm debugger assumes that properties are just properties, and they do not make critical changes to the internal state of objects. Thus, the debugger calls errors getter to show its value in the Variables window when debugging the __ini__ method. And that breaks the normal flow of execution.
(That's why you should define methods like get_error() in such cases, not properties)
One possible suggestion might be to avoid breakpoints and phased execution inside the __init__ form method. But if you really need to debug it, change the code so that the _errors property _errors not exist during step-by-step execution. This will prevent calls to the full_clean method. The PyCharm debugger will receive an error each time it tries to access the errors property.
Note : the errors property can be evaluated at any stage when execution is paused even outside the __init__ method. This will probably not affect the result if all the fields are already fully initialized (do not forget to do this only in the __init__ method). However, you may find that you still cannot debug the form validation process because the form will be validated before you reach the is_valid method is_valid . In this case, set a breakpoint inside the full_clean method and do not stop between the form creation point and this breakpoint.