Skip to content

Commit

Permalink
#2152 on submission change called twice with same status (#2353) (#2355)
Browse files Browse the repository at this point in the history
* #2152 on submission change called twice with same status (#2353)
#2305 normalize components height
resolves #2152 #2305

* unused import

* fix test

* fix tests

---------

Co-authored-by: Fred Lefévère-Laoide <[email protected]>
  • Loading branch information
FredLL-Avaiga and Fred Lefévère-Laoide authored Dec 20, 2024
1 parent 13d97c5 commit cacd400
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 58 deletions.
4 changes: 4 additions & 0 deletions frontend/taipy-gui/public/stylekit/controls/button.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
MODIFIER CLASSES
**************************************************/

.taipy-button {
margin: 4px 0;
}

/* fullwidth : */
.taipy-button.fullwidth {
display: flex;
Expand Down
3 changes: 3 additions & 0 deletions frontend/taipy-gui/public/stylekit/controls/file_download.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
/*************************************************
MODIFIER CLASSES
**************************************************/
.taipy-file-download>button {
margin: 4px 0;
}

/* fullwidth : */
.taipy-file-download.fullwidth button {
Expand Down
3 changes: 3 additions & 0 deletions frontend/taipy-gui/public/stylekit/controls/file_selector.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
/*************************************************
MODIFIER CLASSES
**************************************************/
.taipy-file-selector .MuiButtonBase-root {
margin: 4px 0;
}

/* fullwidth : */
.taipy-file-selector.fullwidth [role='button'] {
Expand Down
2 changes: 1 addition & 1 deletion frontend/taipy-gui/public/stylekit/controls/selector.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
**************************************************/

.taipy-selector {
margin: 0;
margin: 4px 0;
}


Expand Down
1 change: 1 addition & 0 deletions frontend/taipy-gui/public/stylekit/controls/slider.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
max-width: 100%;
min-height: 48px;
align-items: center;
margin: 4px 0;
}
1 change: 1 addition & 0 deletions frontend/taipy-gui/public/stylekit/controls/status.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@
display: inline-flex;
min-height: 48px;
padding-top: 0.5em;
margin: 4px 0;
}
3 changes: 3 additions & 0 deletions frontend/taipy-gui/public/stylekit/controls/toggle.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
/*************************************************
MODIFIER CLASSES
**************************************************/
.taipy-toggle {
margin: 4px 0;
}

/* relative : Reset the theme toggle position to fit page flow */
.taipy-toggle.relative {
Expand Down
100 changes: 48 additions & 52 deletions taipy/gui_core/_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
Sequence,
SequenceId,
Submission,
SubmissionId,
can_create,
cancel_job,
create_scenario,
Expand Down Expand Up @@ -166,67 +165,64 @@ def submission_status_callback(self, submission_id: t.Optional[str] = None, even
if not submission_id:
return
submission = None
new_status = None
new_status: t.Optional[SubmissionStatus] = None
payload: t.Optional[t.Dict[str, t.Any]] = None
client_id: t.Optional[str] = None
submission_name: t.Optional[str] = None
try:
last_client_status = self.client_submission.get(submission_id)
if not last_client_status:
submission = t.cast(Submission, core_get(submission_id))
if not submission or not submission.entity_id:
return
new_status = submission.submission_status

client_id = last_client_status.client_id

with self.gui._get_authorization(client_id):
if not is_readable(t.cast(SubmissionId, submission_id)):
return
submission = t.cast(Submission, core_get(submission_id))
if not submission or not submission.entity_id:
with self.submissions_lock:
last_client_status = self.client_submission.get(submission_id)
if not last_client_status:
return

payload = {}
new_status = t.cast(SubmissionStatus, submission.submission_status)

if client_id:
running_tasks = {}
# with self.gui._get_authorization(client_id):
for job in submission.jobs:
job = job if isinstance(job, Job) else t.cast(Job, core_get(job))
running_tasks[job.task.id] = (
SubmissionStatus.RUNNING.value
if job.is_running()
else SubmissionStatus.PENDING.value
if job.is_pending()
else None
)
payload.update(tasks=running_tasks)

if last_client_status.submission_status is not new_status:
# callback
submission_name = submission.properties.get("on_submission")
if submission_name:
self.gui.invoke_callback(
client_id,
submission_name,
[
core_get(submission.id),
{
"submission_status": new_status.name,
"submittable_entity": core_get(submission.entity_id),
**(event.metadata if event else {}),
},
],
submission.properties.get("module_context"),
if last_client_status.submission_status is not new_status:
# callback
submission_name = submission.properties.get("on_submission")

if new_status in (
SubmissionStatus.COMPLETED,
SubmissionStatus.FAILED,
SubmissionStatus.CANCELED,
):
self.client_submission.pop(submission_id, None)
else:
last_client_status.submission_status = new_status

if client_id:= submission.properties.get("client_id"):
with self.gui._get_authorization(client_id):
if payload is not None:
running_tasks = {}
for job in submission.jobs:
job = job if isinstance(job, Job) else t.cast(Job, core_get(job))
running_tasks[job.task.id] = (
SubmissionStatus.RUNNING.value
if job.is_running()
else SubmissionStatus.PENDING.value
if job.is_pending()
else None
)
payload.update(tasks=running_tasks)

if new_status in (
SubmissionStatus.COMPLETED,
SubmissionStatus.FAILED,
SubmissionStatus.CANCELED,
):
with self.submissions_lock:
self.client_submission.pop(submission_id, None)
else:
last_client_status.submission_status = new_status
if submission_name:
self.gui.invoke_callback(
client_id,
submission_name,
[
core_get(submission.id),
{
"submission_status": new_status.name if new_status else "None",
"submittable_entity": core_get(submission.entity_id),
**(event.metadata if event else {}),
},
],
submission.properties.get("module_context"),
)

except Exception as e:
_warn(f"Submission ({submission_id}) is not available", e)
Expand Down
6 changes: 1 addition & 5 deletions tests/gui_core/test_context_is_readable.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,6 @@ def test_submission_status_callback(self):
assert found is True
mockget.reset_mock()

with patch("taipy.gui_core._context.is_readable", side_effect=mock_is_readable_false):
gui_core_context.submission_status_callback(a_submission.id)
mockget.assert_not_called()

def test_data_node_adapter(self):
with patch("taipy.gui_core._context.core_get", side_effect=mock_core_get):
gui_core_context = _GuiCoreContext(Mock())
Expand Down Expand Up @@ -386,7 +382,7 @@ def test_get_scenarios_for_owner(self):
mockget.reset_mock()

with patch("taipy.gui_core._context.is_readable", side_effect=mock_is_readable_false):
gui_core_context.submission_status_callback(a_scenario.id)
gui_core_context.get_scenarios_for_owner(a_scenario.id)
mockget.assert_not_called()

def test_update_data(self):
Expand Down

0 comments on commit cacd400

Please sign in to comment.