cards: do not add multiple afterjobs for reverse relations of same card (#88725)
This commit is contained in:
parent
d0358afa40
commit
5b4767246c
|
@ -1867,12 +1867,14 @@ def test_carddata_add_edit_related(pub):
|
|||
childdata = child.data_class().select()[0]
|
||||
assert len(childdata.get_workflow_traces()) == 1
|
||||
|
||||
AfterJob.wipe()
|
||||
resp = app.get('/backoffice/data/child/%s/wfedit-_editable?_popup=1' % childdata.id)
|
||||
assert resp.form['f1'].value == 'foo'
|
||||
assert resp.form['f2'].value == 'bar'
|
||||
resp.form['f1'] = 'foo2'
|
||||
resp.form['f2'] = 'bar2'
|
||||
resp = resp.form.submit('submit')
|
||||
assert AfterJob.count() == 1 # check a single job has been created to update relations
|
||||
childdata.refresh_from_storage()
|
||||
assert len(childdata.get_workflow_traces()) == 2
|
||||
|
||||
|
|
|
@ -125,8 +125,13 @@ class CardData(FormData):
|
|||
if self.formdef.reverse_relations:
|
||||
job = UpdateRelationsAfterJob(carddata=self)
|
||||
if get_response():
|
||||
job.store()
|
||||
get_response().add_after_job(job)
|
||||
job._update_key = (self._formdef.id, self.id)
|
||||
# do not register/run job if an identical job is already planned
|
||||
if job._update_key not in (
|
||||
getattr(x, '_update_key', None) for x in get_response().after_jobs or []
|
||||
):
|
||||
job.store()
|
||||
get_response().add_after_job(job)
|
||||
else:
|
||||
job.execute()
|
||||
self._has_changed_digest = False
|
||||
|
|
Loading…
Reference in New Issue