@@ -123,12 +123,13 @@ def add3(a, b):
123123
124124 create .assert_called_once ()
125125 assert create .call_args .args == ("add3" ,)
126- assert create .call_args .kwargs == {"status" : StatusEnum .PENDING , "queue" : "default" }
126+ task_id = create .call_args .kwargs ["task_id" ]
127+ assert create .call_args .kwargs == {"status" : StatusEnum .PENDING , "queue" : "default" , "task_id" : task_id }
127128
128- # The injected id should appear in the Procrastinate job's task kwargs.
129+ # The generated id is passed to create and injected into the Procrastinate job's task kwargs.
129130 jobs = list (app .connector .jobs .values ())
130131 assert len (jobs ) == 1
131- assert jobs [0 ]["args" ][TB_TASK_ID_KWARG ] == tb . id
132+ assert jobs [0 ]["args" ][TB_TASK_ID_KWARG ] == task_id
132133
133134
134135@pytest .mark .usefixtures ("_bind_settings" )
@@ -175,13 +176,13 @@ async def add5(a, b):
175176
176177 tb = task_for_test ()
177178 with (
178- mock .patch ("taskbadger.procrastinate.create_task_safe" , return_value = tb ),
179+ mock .patch ("taskbadger.procrastinate.create_task_safe" , return_value = tb ) as create ,
179180 mock .patch ("taskbadger.procrastinate.update_task_safe" ),
180181 ):
181182 asyncio .run (add5 .defer_async (a = 1 , b = 2 ))
182183
183184 jobs = list (app .connector .jobs .values ())
184- assert jobs [0 ]["args" ][TB_TASK_ID_KWARG ] == tb . id
185+ assert jobs [0 ]["args" ][TB_TASK_ID_KWARG ] == create . call_args . kwargs [ "task_id" ]
185186
186187
187188@pytest .mark .usefixtures ("_bind_settings" )
@@ -194,12 +195,12 @@ def add_ext(a, b):
194195
195196 tb = task_for_test ()
196197 with (
197- mock .patch ("taskbadger.procrastinate.create_task_safe" , return_value = tb ),
198+ mock .patch ("taskbadger.procrastinate.create_task_safe" , return_value = tb ) as create ,
198199 mock .patch ("taskbadger.procrastinate.update_task_safe" ) as update ,
199200 ):
200201 job_id = add_ext .defer (a = 1 , b = 2 )
201202
202- update .assert_called_once_with (tb . id , external_id = str (job_id ))
203+ update .assert_called_once_with (create . call_args . kwargs [ "task_id" ] , external_id = str (job_id ))
203204
204205
205206@pytest .mark .usefixtures ("_bind_settings" )
@@ -212,12 +213,12 @@ async def add_ext_async(a, b):
212213
213214 tb = task_for_test ()
214215 with (
215- mock .patch ("taskbadger.procrastinate.create_task_safe" , return_value = tb ),
216+ mock .patch ("taskbadger.procrastinate.create_task_safe" , return_value = tb ) as create ,
216217 mock .patch ("taskbadger.procrastinate.update_task_safe" ) as update ,
217218 ):
218219 job_id = asyncio .run (add_ext_async .defer_async (a = 1 , b = 2 ))
219220
220- update .assert_called_once_with (tb . id , external_id = str (job_id ))
221+ update .assert_called_once_with (create . call_args . kwargs [ "task_id" ] , external_id = str (job_id ))
221222
222223
223224def test_defer_no_external_id_when_untracked (app ):
@@ -269,15 +270,15 @@ def bare(a):
269270
270271 tb = task_for_test ()
271272 with (
272- mock .patch ("taskbadger.procrastinate.create_task_safe" , return_value = tb ),
273+ mock .patch ("taskbadger.procrastinate.create_task_safe" , return_value = tb ) as create ,
273274 mock .patch ("taskbadger.procrastinate.update_task_safe" ),
274275 ):
275276 bare .defer (a = 1 )
276277
277278 assert getattr (bare , "_taskbadger_manual" ) is True
278279 # Inspect the actual Procrastinate job - jobs is a dict keyed by int, kwargs under "args"
279280 jobs = list (app .connector .jobs .values ())
280- assert jobs [0 ]["args" ][TB_TASK_ID_KWARG ] == tb . id
281+ assert jobs [0 ]["args" ][TB_TASK_ID_KWARG ] == create . call_args . kwargs [ "task_id" ]
281282
282283
283284@pytest .mark .usefixtures ("_bind_settings" )
@@ -296,12 +297,14 @@ def raw(a):
296297
297298 create .assert_called_once ()
298299 assert create .call_args .args == ("custom" ,)
300+ task_id = create .call_args .kwargs ["task_id" ]
299301 assert create .call_args .kwargs == {
300302 "status" : StatusEnum .PENDING ,
301303 "value_max" : 10 ,
302304 "tags" : {"env" : "test" },
303305 "data" : {"k" : "v" },
304306 "queue" : "default" ,
307+ "task_id" : task_id ,
305308 }
306309
307310
0 commit comments