summaryrefslogtreecommitdiff
path: root/tests/async
diff options
context:
space:
mode:
authorAivars Kalvans <aivars.kalvans@gmail.com>2023-12-10 21:43:34 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2024-01-15 10:55:14 +0100
commitf92641a636a8cb75fc9851396cef4345510a4b52 (patch)
treeea37f35d62ca5807678c37de2292f8600ab22d6f /tests/async
parentf3d10546a850df4fe3796f972d5b7e16adf52f54 (diff)
Fixed #28344 -- Allowed customizing queryset in Model.refresh_from_db()/arefresh_from_db().
The from_queryset parameter can be used to: - use a custom Manager - lock the row until the end of transaction - select additional related objects
Diffstat (limited to 'tests/async')
-rw-r--r--tests/async/test_async_model_methods.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/async/test_async_model_methods.py b/tests/async/test_async_model_methods.py
index 94e0370e35..d988d7befc 100644
--- a/tests/async/test_async_model_methods.py
+++ b/tests/async/test_async_model_methods.py
@@ -23,3 +23,14 @@ class AsyncModelOperationTest(TestCase):
await SimpleModel.objects.filter(pk=self.s1.pk).aupdate(field=20)
await self.s1.arefresh_from_db()
self.assertEqual(self.s1.field, 20)
+
+ async def test_arefresh_from_db_from_queryset(self):
+ await SimpleModel.objects.filter(pk=self.s1.pk).aupdate(field=20)
+ with self.assertRaises(SimpleModel.DoesNotExist):
+ await self.s1.arefresh_from_db(
+ from_queryset=SimpleModel.objects.filter(field=0)
+ )
+ await self.s1.arefresh_from_db(
+ from_queryset=SimpleModel.objects.filter(field__gt=0)
+ )
+ self.assertEqual(self.s1.field, 20)