mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #30375 -- Added FOR NO KEY UPDATE support to QuerySet.select_for_update() on PostgreSQL.
This commit is contained in:
committed by
Mariusz Felisiak
parent
0e893248b2
commit
a4e6030904
@@ -97,6 +97,16 @@ class SelectForUpdateTests(TransactionTestCase):
|
||||
list(Person.objects.all().select_for_update(skip_locked=True))
|
||||
self.assertTrue(self.has_for_update_sql(ctx.captured_queries, skip_locked=True))
|
||||
|
||||
@skipUnlessDBFeature('has_select_for_no_key_update')
|
||||
def test_update_sql_generated_no_key(self):
|
||||
"""
|
||||
The backend's FOR NO KEY UPDATE variant appears in generated SQL when
|
||||
select_for_update() is invoked.
|
||||
"""
|
||||
with transaction.atomic(), CaptureQueriesContext(connection) as ctx:
|
||||
list(Person.objects.all().select_for_update(no_key=True))
|
||||
self.assertIs(self.has_for_update_sql(ctx.captured_queries, no_key=True), True)
|
||||
|
||||
@skipUnlessDBFeature('has_select_for_update_of')
|
||||
def test_for_update_sql_generated_of(self):
|
||||
"""
|
||||
@@ -291,6 +301,18 @@ class SelectForUpdateTests(TransactionTestCase):
|
||||
with transaction.atomic():
|
||||
Person.objects.select_for_update(of=('self',)).get()
|
||||
|
||||
@skipIfDBFeature('has_select_for_no_key_update')
|
||||
@skipUnlessDBFeature('has_select_for_update')
|
||||
def test_unsuported_no_key_raises_error(self):
|
||||
"""
|
||||
NotSupportedError is raised if a SELECT...FOR NO KEY UPDATE... is run
|
||||
on a database backend that supports FOR UPDATE but not NO KEY.
|
||||
"""
|
||||
msg = 'FOR NO KEY UPDATE is not supported on this database backend.'
|
||||
with self.assertRaisesMessage(NotSupportedError, msg):
|
||||
with transaction.atomic():
|
||||
Person.objects.select_for_update(no_key=True).get()
|
||||
|
||||
@skipUnlessDBFeature('has_select_for_update', 'has_select_for_update_of')
|
||||
def test_unrelated_of_argument_raises_error(self):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user