diff options
| author | Clifford Gama <cliffygamy@gmail.com> | 2025-05-16 23:48:38 +0200 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-06-18 08:36:49 +0200 |
| commit | 74b31cd26b9ad4ad85f131850a734f02aae988bb (patch) | |
| tree | ceabf0b4c985ae8159d44cf969e17c31bd38a337 /django/contrib/postgres/fields/array.py | |
| parent | 8c56e939750ae785b806dfa4e043590760c90ab6 (diff) | |
Fixed #32770 -- Added system check to ensure django.contrib.postgres is installed when using its features.
Added postgres.E005 to validate 'django.contrib.postgres' is in INSTALLED_APPS
when using:
* PostgreSQL-specific fields (ArrayField, HStoreField, range fields, SearchVectorField),
* PostgreSQL indexes (PostgresIndex and all subclasses), and
* ExclusionConstraint
The check provides immediate feedback during system checks rather than failing
later with obscure runtime and database errors.
Thanks to Simon Charette and Sarah Boyce for reviews.
Diffstat (limited to 'django/contrib/postgres/fields/array.py')
| -rw-r--r-- | django/contrib/postgres/fields/array.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/django/contrib/postgres/fields/array.py b/django/contrib/postgres/fields/array.py index 88df368c73..ac663830f8 100644 --- a/django/contrib/postgres/fields/array.py +++ b/django/contrib/postgres/fields/array.py @@ -9,13 +9,13 @@ from django.db.models.fields.mixins import CheckFieldDefaultMixin from django.db.models.lookups import Exact, In from django.utils.translation import gettext_lazy as _ -from ..utils import prefix_validation_error +from ..utils import CheckPostgresInstalledMixin, prefix_validation_error from .utils import AttributeSetter __all__ = ["ArrayField"] -class ArrayField(CheckFieldDefaultMixin, Field): +class ArrayField(CheckPostgresInstalledMixin, CheckFieldDefaultMixin, Field): empty_strings_allowed = False default_error_messages = { "item_invalid": _("Item %(nth)s in the array did not validate:"), @@ -73,6 +73,8 @@ class ArrayField(CheckFieldDefaultMixin, Field): "%s (%s)" % (base_check.msg, base_check.id) for base_check in base_checks if isinstance(base_check, checks.Error) + # Prevent duplication of E005 in an E001 check. + and not base_check.id == "postgres.E005" ) if error_messages: errors.append( |
