|
13 | 13 | Event, |
14 | 14 | IntFields, |
15 | 15 | JSONFields, |
| 16 | + Reporter, |
16 | 17 | Service, |
17 | 18 | SmallIntFields, |
18 | 19 | SourceFieldPk, |
|
21 | 22 | ) |
22 | 23 | from tortoise.contrib import test |
23 | 24 | from tortoise.contrib.test.condition import In, NotEQ |
24 | | -from tortoise.expressions import Case, F, Q, When |
| 25 | +from tortoise.expressions import Case, F, Q, Subquery, When |
25 | 26 | from tortoise.functions import Function, Upper |
26 | 27 |
|
27 | 28 |
|
@@ -246,3 +247,18 @@ async def test_update_with_function_annotation(self): |
246 | 247 | .update(name=F("upped_name")) |
247 | 248 | ) |
248 | 249 | self.assertEqual((await Tournament.get(pk=tournament.pk)).name, "AAA") |
| 250 | + |
| 251 | + async def test_update_with_filter_subquery(self): |
| 252 | + t1 = await Tournament.create(name="1") |
| 253 | + r1 = await Reporter.create(name="1") |
| 254 | + e1 = await Event.create(name="1", tournament=t1, reporter=r1) |
| 255 | + |
| 256 | + # NOTE: this is intentionally written with Subquery and known PKs to test |
| 257 | + # whether subqueries are parameterized correctly. |
| 258 | + await Event.filter( |
| 259 | + tournament_id__in=Subquery(Tournament.filter(pk__in=[t1.pk]).values("id")), |
| 260 | + reporter_id__in=Subquery(Reporter.filter(pk__in=[r1.pk]).values("id")), |
| 261 | + ).update(token="hello_world") |
| 262 | + |
| 263 | + await e1.refresh_from_db(fields=["token"]) |
| 264 | + self.assertEqual(e1.token, "hello_world") |
0 commit comments