Rerender form without validation

Hi, I’m using Unpoly which has a feature (up-validate) that submits a forms with a request header so that I could rerender my form with new information (like pre-populate some other fields).

I can, on my view, check for that header and recreate the form with the new information.

My problem is that, even if I don’t call is_valid(), on sending the form back, the form has errors.

Is there a way to avoid that validation (my guess it’s the model validation kicking in since this is the form is a ModelForm).

Update: even with a non-ModelForm, it still has errors before is_valid().

    def post(self, request):
        if request.is_up_validate: <---- Middleware that checks Unpoly header
            some_id = request.POST.get('some_id', None)

            form = SomethingForm(
                request.POST,
                user_id=request.user.id,
                some_id=some_id
            )

            logger.debug (form.errors) <---- Form has errors

            return render(request, 'template_name.html', {'form': form})

TIA

This isn’t quite a fully-accurate statement.

The errors in a form are stored in an internal attribute named _errors. This dict is populated by the full_clean method. There are a number of different ways that full_clean can end up being called, and is_valid is only one of them. Referencing the errors attribute of the form will also cause full_clean to be called if it hasn’t already been done.

In other words, this statement:

would actually cause full_clean to be called.

If I were to make a guess, you could probably set form._errors = ErrorDict() after binding the form. Or, you may be able to override the full_clean method to reset the _errors attribute after the other processing has been done.

Thanks for the detailed explanation. The proposed solution withErrorDict() worked just fine. :slight_smile: