From 74b31cd26b9ad4ad85f131850a734f02aae988bb Mon Sep 17 00:00:00 2001 From: Clifford Gama Date: Fri, 16 May 2025 23:48:38 +0200 Subject: 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. --- django/contrib/postgres/fields/array.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'django/contrib/postgres/fields/array.py') 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( -- cgit v1.3