summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2024-07-03 07:51:50 -0400
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-07-04 11:35:03 +0200
commit31837dbcb36f1ab57fb1b16cb0b126c55a1bdf01 (patch)
tree6b99038a1fb308be9e208eebdf0c138e07da2b9b
parent704192e478885762411252979021771ba23b8adb (diff)
Fixed #35569 -- Improved wording of invalid ForeignKey error message.
-rw-r--r--django/db/models/fields/related.py4
-rw-r--r--tests/auth_tests/test_management.py8
-rw-r--r--tests/validation/tests.py9
3 files changed, 13 insertions, 8 deletions
diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
index 7d42d1ea38..8930d6ef4a 100644
--- a/django/db/models/fields/related.py
+++ b/django/db/models/fields/related.py
@@ -929,7 +929,9 @@ class ForeignKey(ForeignObject):
empty_strings_allowed = False
default_error_messages = {
- "invalid": _("%(model)s instance with %(field)s %(value)r does not exist.")
+ "invalid": _(
+ "%(model)s instance with %(field)s %(value)r is not a valid choice."
+ )
}
description = _("Foreign Key (type determined by related field)")
diff --git a/tests/auth_tests/test_management.py b/tests/auth_tests/test_management.py
index 5765c50034..8dd91cf6ed 100644
--- a/tests/auth_tests/test_management.py
+++ b/tests/auth_tests/test_management.py
@@ -523,7 +523,7 @@ class CreatesuperuserManagementCommandTestCase(TestCase):
self.assertEqual(u.group, group)
non_existent_email = "mymail2@gmail.com"
- msg = "email instance with email %r does not exist." % non_existent_email
+ msg = "email instance with email %r is not a valid choice." % non_existent_email
with self.assertRaisesMessage(CommandError, msg):
call_command(
"createsuperuser",
@@ -594,7 +594,7 @@ class CreatesuperuserManagementCommandTestCase(TestCase):
email = Email.objects.create(email="mymail@gmail.com")
Group.objects.all().delete()
nonexistent_group_id = 1
- msg = f"group instance with id {nonexistent_group_id} does not exist."
+ msg = f"group instance with id {nonexistent_group_id} is not a valid choice."
with self.assertRaisesMessage(CommandError, msg):
call_command(
@@ -611,7 +611,7 @@ class CreatesuperuserManagementCommandTestCase(TestCase):
email = Email.objects.create(email="mymail@gmail.com")
Group.objects.all().delete()
nonexistent_group_id = 1
- msg = f"group instance with id {nonexistent_group_id} does not exist."
+ msg = f"group instance with id {nonexistent_group_id} is not a valid choice."
with mock.patch.dict(
os.environ,
@@ -631,7 +631,7 @@ class CreatesuperuserManagementCommandTestCase(TestCase):
email = Email.objects.create(email="mymail@gmail.com")
Group.objects.all().delete()
nonexistent_group_id = 1
- msg = f"group instance with id {nonexistent_group_id} does not exist."
+ msg = f"group instance with id {nonexistent_group_id} is not a valid choice."
@mock_inputs(
{
diff --git a/tests/validation/tests.py b/tests/validation/tests.py
index 6bb04f6f14..494310e553 100644
--- a/tests/validation/tests.py
+++ b/tests/validation/tests.py
@@ -31,15 +31,18 @@ class BaseModelValidationTests(ValidationAssertions, TestCase):
self.assertFieldFailsValidationWithMessage(
mtv.full_clean,
"parent",
- ["model to validate instance with id %r does not exist." % mtv.parent_id],
+ [
+ "model to validate instance with id %r is not a valid choice."
+ % mtv.parent_id
+ ],
)
mtv = ModelToValidate(number=10, name="Some Name", ufm_id="Some Name")
self.assertFieldFailsValidationWithMessage(
mtv.full_clean,
"ufm",
[
- "unique fields model instance with unique_charfield %r does not exist."
- % mtv.name
+ "unique fields model instance with unique_charfield %r is not "
+ "a valid choice." % mtv.name
],
)