diff options
| author | SaJH <wogur981208@gmail.com> | 2025-09-15 19:55:55 -0400 |
|---|---|---|
| committer | Jacob Walls <jacobtylerwalls@gmail.com> | 2025-09-16 10:25:16 -0400 |
| commit | 8c621e96422e037c3997c8c9515bc050620852f6 (patch) | |
| tree | a8ceae664ea5940bc1776722eae36a489d534f6f /tests/foreign_object | |
| parent | 308f674e6d0a89653b5071a2b0cfbf5747b33c89 (diff) | |
Fixed #36580 -- Fixed constraint validation crash when condition uses a ForeignObject.
Follow-up to e44e8327d3d88d86895735c0e427102063ff5b55. Refs #36222.
Diffstat (limited to 'tests/foreign_object')
| -rw-r--r-- | tests/foreign_object/tests.py | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/tests/foreign_object/tests.py b/tests/foreign_object/tests.py index 436d9583c4..09fb47e771 100644 --- a/tests/foreign_object/tests.py +++ b/tests/foreign_object/tests.py @@ -3,10 +3,10 @@ import datetime import pickle from operator import attrgetter -from django.core.exceptions import FieldError +from django.core.exceptions import FieldError, ValidationError from django.db import connection, models from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature -from django.test.utils import isolate_apps +from django.test.utils import CaptureQueriesContext, isolate_apps from django.utils import translation from .models import ( @@ -772,6 +772,29 @@ class TestCachedPathInfo(TestCase): class ForeignObjectModelValidationTests(TestCase): @skipUnlessDBFeature("supports_table_check_constraints") + def test_validate_constraints_with_foreign_object(self): + customer_tab = CustomerTab(customer_id=1500) + with self.assertRaisesMessage(ValidationError, "customer_id_limit"): + customer_tab.validate_constraints() + + @skipUnlessDBFeature("supports_table_check_constraints") + def test_validate_constraints_success_case_single_query(self): + customer_tab = CustomerTab(customer_id=500) + with CaptureQueriesContext(connection) as ctx: + customer_tab.validate_constraints() + select_queries = [ + query["sql"] + for query in ctx.captured_queries + if "select" in query["sql"].lower() + ] + self.assertEqual(len(select_queries), 1) + + @skipUnlessDBFeature("supports_table_check_constraints") def test_validate_constraints_excluding_foreign_object(self): customer_tab = CustomerTab(customer_id=150) customer_tab.validate_constraints(exclude={"customer"}) + + @skipUnlessDBFeature("supports_table_check_constraints") + def test_validate_constraints_excluding_foreign_object_member(self): + customer_tab = CustomerTab(customer_id=150) + customer_tab.validate_constraints(exclude={"customer_id"}) |
