Skip to content

Commit 2330cd8

Browse files
committed
Clarified Default vs ClassName groups
1 parent a21fb26 commit 2330cd8

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

book/validation.rst

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -807,10 +807,11 @@ user registers and when a user updates their contact information later:
807807
}
808808
}
809809
810-
With this configuration, there are two validation groups:
810+
With this configuration, there are three validation groups:
811811

812-
* ``User`` - contains the constraints that belong to no other group,
813-
and is considered the ``Default`` group. (This group is useful for
812+
* ``User`` - contains the constraints that belong to no other group;
813+
814+
* ``Default`` - equivalent to the ``User`` group (This group is useful for
814815
:ref:`book-validation-group-sequence`);
815816

816817
* ``registration`` - contains the constraints on the ``email`` and ``password``
@@ -837,13 +838,8 @@ Group Sequence
837838
--------------
838839

839840
In some cases, you want to validate your groups by steps. To do this, you can
840-
use the ``GroupSequence`` feature. In the case, an object defines a group sequence,
841-
and then the groups in the group sequence are validated in order.
842-
843-
.. tip::
844-
845-
Group sequences cannot contain the group ``Default``, as this would create
846-
a loop. Instead, use the group ``{ClassName}`` (e.g. ``User``).
841+
use the ``GroupSequence`` feature. In this case, an object defines a group sequence
842+
, which determines the order groups should be validated.
847843

848844
For example, suppose you have a ``User`` class and want to validate that the
849845
username and the password are different only if all other validation passes
@@ -968,6 +964,20 @@ In this example, it will first validate all constraints in the group ``User``
968964
(which is the same as the ``Default`` group). Only if all constraints in
969965
that group are valid, the second group, ``Strict``, will be validated.
970966

967+
.. caution::
968+
969+
As you have already seen in the previous section, the ``Default`` group
970+
and the group containing the class name (e.g. ``User``) were identical.
971+
However, when using Group Sequences, they are no longer identical. The
972+
``Default`` group will now reference the group sequence, instead of all
973+
constraints that do not belong to any group.
974+
975+
This means that you have to use the ``{ClassName}`` (e.g. ``User``) group
976+
when specifing a group sequence. When using ``Default``, you get an
977+
infinite recursion (as the ``Default`` groups references the group
978+
sequence, which will contain the ``Default`` group which references the
979+
same group sequence, ...).
980+
971981
Group Sequence Providers
972982
~~~~~~~~~~~~~~~~~~~~~~~~
973983

0 commit comments

Comments
 (0)