@@ -136,6 +136,39 @@ def test_ti_run_state_conflict_if_not_queued(
136
136
137
137
assert session .scalar (select (TaskInstance .state ).where (TaskInstance .id == ti .id )) == initial_ti_state
138
138
139
+ def test_ti_run_failed_with_extra (self , client , session , create_task_instance , time_machine ):
140
+ """
141
+ Test that a 422 error is returned when extra fields are included in the payload.
142
+ """
143
+ instant_str = "2024-12-19T00:00:00Z"
144
+ instant = timezone .parse (instant_str )
145
+ time_machine .move_to (instant , tick = False )
146
+
147
+ ti = create_task_instance (
148
+ task_id = "test_ti_run_failed_with_extra" ,
149
+ state = State .QUEUED ,
150
+ session = session ,
151
+ start_date = instant ,
152
+ )
153
+
154
+ session .commit ()
155
+
156
+ response = client .patch (
157
+ f"/execution/task-instances/{ ti .id } /run" ,
158
+ json = {
159
+ "state" : "running" ,
160
+ "hostname" : "random-hostname" ,
161
+ "unixname" : "random-unixname" ,
162
+ "pid" : 100 ,
163
+ "start_date" : instant_str ,
164
+ "foo" : "bar" ,
165
+ },
166
+ )
167
+
168
+ assert response .status_code == 422
169
+ assert response .json ()["detail" ][0 ]["type" ] == "extra_forbidden"
170
+ assert response .json ()["detail" ][0 ]["msg" ] == "Extra inputs are not permitted"
171
+
139
172
140
173
class TestTIUpdateState :
141
174
def setup_method (self ):
@@ -340,6 +373,27 @@ def test_ti_update_state_to_reschedule(self, client, session, create_task_instan
340
373
assert trs [0 ].map_index == - 1
341
374
assert trs [0 ].duration == 129600
342
375
376
+ def test_ti_update_state_failed_with_extra (self , client , session , create_task_instance , time_machine ):
377
+ """
378
+ Test that a 422 error is returned when extra fields are included in the payload.
379
+ """
380
+ ti = create_task_instance (
381
+ task_id = "test_ti_update_state_failed_with_extra" ,
382
+ state = State .RUNNING ,
383
+ session = session ,
384
+ start_date = DEFAULT_START_DATE ,
385
+ )
386
+
387
+ session .commit ()
388
+
389
+ response = client .patch (
390
+ f"/execution/task-instances/{ ti .id } /state" , json = {"state" : "scheduled" , "foo" : "bar" }
391
+ )
392
+
393
+ assert response .status_code == 422
394
+ assert response .json ()["detail" ][0 ]["type" ] == "extra_forbidden"
395
+ assert response .json ()["detail" ][0 ]["msg" ] == "Extra inputs are not permitted"
396
+
343
397
344
398
class TestTIHealthEndpoint :
345
399
def setup_method (self ):
@@ -536,6 +590,35 @@ def test_ti_update_state_to_failed_table_check(self, client, session, create_tas
536
590
assert ti .next_kwargs is None
537
591
assert ti .duration == 3600.00
538
592
593
+ def test_ti_heartbeat_with_extra (
594
+ self ,
595
+ client ,
596
+ session ,
597
+ create_task_instance ,
598
+ time_machine ,
599
+ ):
600
+ """
601
+ Test that a 422 error is returned when extra fields are included in the payload.
602
+ """
603
+ ti = create_task_instance (
604
+ task_id = "test_ti_heartbeat_when_task_not_running" ,
605
+ state = State .RUNNING ,
606
+ hostname = "random-hostname" ,
607
+ pid = 1547 ,
608
+ session = session ,
609
+ )
610
+ session .commit ()
611
+ task_instance_id = ti .id
612
+
613
+ response = client .put (
614
+ f"/execution/task-instances/{ task_instance_id } /heartbeat" ,
615
+ json = {"hostname" : "random-hostname" , "pid" : 1547 , "foo" : "bar" },
616
+ )
617
+
618
+ assert response .status_code == 422
619
+ assert response .json ()["detail" ][0 ]["type" ] == "extra_forbidden"
620
+ assert response .json ()["detail" ][0 ]["msg" ] == "Extra inputs are not permitted"
621
+
539
622
540
623
class TestTIPutRTIF :
541
624
def setup_method (self ):
0 commit comments