Fixed #33724 -- Doc'd exclude argument changes in model validation.

Thanks אורי for the report.

Follow up to 1ea7e3157d.
This commit is contained in:
Mariusz Felisiak 2022-05-24 10:02:53 +02:00 committed by GitHub
parent 241fe59b74
commit 90aabd730a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 8 deletions

View File

@ -224,8 +224,8 @@ This method calls :meth:`Model.clean_fields()`, :meth:`Model.clean()`,
in that order and raises a :exc:`~django.core.exceptions.ValidationError` that in that order and raises a :exc:`~django.core.exceptions.ValidationError` that
has a ``message_dict`` attribute containing errors from all four stages. has a ``message_dict`` attribute containing errors from all four stages.
The optional ``exclude`` argument can be used to provide a list of field names The optional ``exclude`` argument can be used to provide a ``set`` of field
that can be excluded from validation and cleaning. names that can be excluded from validation and cleaning.
:class:`~django.forms.ModelForm` uses this argument to exclude fields that :class:`~django.forms.ModelForm` uses this argument to exclude fields that
aren't present on your form from being validated since any errors raised could aren't present on your form from being validated since any errors raised could
not be corrected by the user. not be corrected by the user.
@ -249,12 +249,16 @@ The first step ``full_clean()`` performs is to clean each individual field.
The ``validate_constraints`` argument was added. The ``validate_constraints`` argument was added.
.. versionchanged:: 4.1
An ``exclude`` value is now converted to a ``set`` rather than a ``list``.
.. method:: Model.clean_fields(exclude=None) .. method:: Model.clean_fields(exclude=None)
This method will validate all fields on your model. The optional ``exclude`` This method will validate all fields on your model. The optional ``exclude``
argument lets you provide a list of field names to exclude from validation. It argument lets you provide a ``set`` of field names to exclude from validation.
will raise a :exc:`~django.core.exceptions.ValidationError` if any fields fail It will raise a :exc:`~django.core.exceptions.ValidationError` if any fields
validation. fail validation.
The second step ``full_clean()`` performs is to call :meth:`Model.clean()`. The second step ``full_clean()`` performs is to call :meth:`Model.clean()`.
This method should be overridden to perform custom validation on your model. This method should be overridden to perform custom validation on your model.
@ -355,8 +359,8 @@ uniqueness constraints defined via :attr:`.Field.unique`,
:attr:`.Field.unique_for_date`, :attr:`.Field.unique_for_month`, :attr:`.Field.unique_for_date`, :attr:`.Field.unique_for_month`,
:attr:`.Field.unique_for_year`, or :attr:`Meta.unique_together :attr:`.Field.unique_for_year`, or :attr:`Meta.unique_together
<django.db.models.Options.unique_together>` on your model instead of individual <django.db.models.Options.unique_together>` on your model instead of individual
field values. The optional ``exclude`` argument allows you to provide a list of field values. The optional ``exclude`` argument allows you to provide a ``set``
field names to exclude from validation. It will raise a of field names to exclude from validation. It will raise a
:exc:`~django.core.exceptions.ValidationError` if any fields fail validation. :exc:`~django.core.exceptions.ValidationError` if any fields fail validation.
:class:`~django.db.models.UniqueConstraint`\s defined in the :class:`~django.db.models.UniqueConstraint`\s defined in the
@ -380,7 +384,7 @@ Finally, ``full_clean()`` will check any other constraints on your model.
This method validates all constraints defined in This method validates all constraints defined in
:attr:`Meta.constraints <django.db.models.Options.constraints>`. The :attr:`Meta.constraints <django.db.models.Options.constraints>`. The
optional ``exclude`` argument allows you to provide a list of field names to optional ``exclude`` argument allows you to provide a ``set`` of field names to
exclude from validation. It will raise a exclude from validation. It will raise a
:exc:`~django.core.exceptions.ValidationError` if any constraints fail :exc:`~django.core.exceptions.ValidationError` if any constraints fail
validation. validation.

View File

@ -561,6 +561,12 @@ Miscellaneous
``URLResolver._callback_strs``, and ``URLPattern.lookup_str()`` are ``URLResolver._callback_strs``, and ``URLPattern.lookup_str()`` are
moved to ``django.contrib.admindocs.utils``. moved to ``django.contrib.admindocs.utils``.
* The :meth:`.Model.full_clean` method now converts an ``exclude`` value to the
``set``. Its also preferable to pass an ``exclude`` value as a ``set`` to
the :meth:`.Model.clean_fields`, :meth:`.Model.full_clean`,
:meth:`.Model.validate_unique`, and :meth:`.Model.validate_constraints`
methods.
.. _deprecated-features-4.1: .. _deprecated-features-4.1:
Features deprecated in 4.1 Features deprecated in 4.1