#33724: Changing from list to set in `exclude` raises errors, and is not documented. -------------------------------------+------------------------------------- Reporter: אורי | Owner: nobody Type: Bug | Status: new Component: Database layer | Version: 4.1 (models, ORM) | Severity: Release blocker | Resolution: Keywords: | Triage Stage: Accepted Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------- Changes (by Mariusz Felisiak):
* cc: Carlton Gibson (added) Comment: Replying to [comment:6 Claude Paroz]: > Still I wonder if the performance gain is worth the loss of consistency. I wouldn't mind if exclude was defined to always be a set, but having to code defensively by expecting list or set is a loss in my point of view. All built-in methods do exactly the same number of conversion as before 1ea7e3157d1f9b4db71e768d75ea57e47dbd49f9 just using `set(...)` instead of `list(...)`. IMO we can document `set` as the preferable option, e.g. {{{#!diff diff --git a/docs/ref/models/instances.txt b/docs/ref/models/instances.txt index 9aa9486f4a..8601a19e64 100644 --- a/docs/ref/models/instances.txt +++ b/docs/ref/models/instances.txt @@ -252,9 +252,9 @@ The first step ``full_clean()`` performs is to clean each individual field. .. method:: Model.clean_fields(exclude=None) 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 -will raise a :exc:`~django.core.exceptions.ValidationError` if any fields fail -validation. +argument lets you provide a ``set`` of field names to exclude from validation. +It will raise a :exc:`~django.core.exceptions.ValidationError` if any fields +fail validation. The second step ``full_clean()`` performs is to call :meth:`Model.clean()`. This method should be overridden to perform custom validation on your model. @@ -355,8 +355,8 @@ uniqueness constraints defined via :attr:`.Field.unique`, :attr:`.Field.unique_for_date`, :attr:`.Field.unique_for_month`, :attr:`.Field.unique_for_year`, or :attr:`Meta.unique_together <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 names to exclude from validation. It will raise a +field values. The optional ``exclude`` argument allows you to provide a ``set`` +of field names to exclude from validation. It will raise a :exc:`~django.core.exceptions.ValidationError` if any fields fail validation. :class:`~django.db.models.UniqueConstraint`\s defined in the @@ -380,7 +380,7 @@ Finally, ``full_clean()`` will check any other constraints on your model. This method validates all constraints defined in :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 :exc:`~django.core.exceptions.ValidationError` if any constraints fail validation. diff --git a/docs/releases/4.1.txt b/docs/releases/4.1.txt index 7b922256ec..a1ec53e2ac 100644 --- a/docs/releases/4.1.txt +++ b/docs/releases/4.1.txt @@ -561,6 +561,10 @@ Miscellaneous ``URLResolver._callback_strs``, and ``URLPattern.lookup_str()`` are moved to ``django.contrib.admindocs.utils``. +* Custom :meth:`.Model.clean_fields`, :meth:`.Model.validate_unique`, and + :meth:`.Model.validate_constraints` methods now convert an ``exclude`` + value to the ``set``. + .. _deprecated-features-4.1: }}} Also, passing lists still works, but would not be documented anymore. What do you think? -- Ticket URL: <https://code.djangoproject.com/ticket/33724#comment:9> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/01070180e0ccf889-0512b872-e3c8-4b8b-9a49-b0155b3d1f67-000000%40eu-central-1.amazonses.com.