Avaiga / taipy

Turns Data and AI algorithms into production-ready web applications in no time.
https://www.taipy.io
Apache License 2.0
10.94k stars 775 forks source link

BUG- on_submission_change called twice with same status #357

Closed FlorianJacta closed 7 months ago

FlorianJacta commented 10 months ago

Issue

The callback is called twice with the same status.

How to replicate

Run this code and see that two notifications are emitted.

from taipy.config import Config
import taipy as tp
from taipy.gui import Gui, notify

# Normal function used by Taipy
def double(nb):
    return nb * 2

def add(nb):
    return nb + 10

# Configuration of Data Nodes
input_cfg = Config.configure_data_node("input", default_data=21)
intermediate_cfg = Config.configure_data_node("intermediate")
output_cfg = Config.configure_data_node("output")

# Configuration of tasks
first_task_cfg = Config.configure_task("double",
                                       double,
                                       input_cfg,
                                       intermediate_cfg)

second_task_cfg = Config.configure_task("add",
                                        add,
                                        intermediate_cfg,
                                        output_cfg)

# Configuration of scenario
scenario_cfg = Config.configure_scenario(id="my_scenario",
                                         task_configs=[first_task_cfg, second_task_cfg],
                                         name="my_scenario")

def notify_from_submissions(state, submittable, details):
    submission_status = details.get('submission_status')

    if submission_status == 'COMPLETED':
        print(f"{[submittable.name](http://submittable.name/)} has completed.")
        notify(state, 'success', 'Completed!')
        # Add additional actions here, like updating the GUI or logging the completion.

    elif submission_status == 'FAILED':
        print(f"{[submittable.name](http://submittable.name/)} has failed.")
        notify(state, 'error', 'Completed!')
        # Handle failure, like sending notifications or logging the error.

if __name__=="__main__":
    tp.Core().run()
    scenario_1 = tp.create_scenario(scenario_cfg)

    scenario_1.submit(wait=True)

    scenario_md = """
<|{scenario_1}|scenario|on_submission_change=notify_from_submissions|>
<|{scenario_1.output if scenario_1 else None}|data_node|>
"""
    Gui(scenario_md).run()

Environment

Taipy 3.0

FredLL-Avaiga commented 10 months ago

Needs a blocking event queue to make event management cleaner

jrobinAV commented 8 months ago

IS it a duplicate or the ticket #475 ?

FlorianJacta commented 8 months ago

Yes, it is a duplicate. I guess I wanted it to be solved, or my memory is fading. Do I close the other issue?

jrobinAV commented 8 months ago

Yes, it is a duplicate. I guess I wanted it to be solved, or my memory is fading. Do I close the other issue?

YEs please @FlorianJacta.

toan-quach commented 8 months ago

Hi @FlorianJacta I was able to reproduce it with 3.0 but not with 3.1dev. I think the issue has been fixed!

@jrobinAV @FredLL-Avaiga I believe no fixes need to be made, but will make some changes to make some of the conditions correct. However, I must note that the on_submission_change doesn't run on development mode but does run in standalone mode, which is to be expected I think

FredLL-Avaiga commented 8 months ago

I don't understand why it runs in one mode and not in another one ?

toan-quach commented 8 months ago

because in development mode, after submitting the scenario, it will run it immediately without stopping until finished. Meaning the submission entity has complete status when we're creating the _SubmissionDetails. No status change will happen after that and so the function was not called as it depends on the change in status of the job (previously, now it's submission status)

FredLL-Avaiga commented 8 months ago

that would need to be documented Or better find a workaround to make it work in dev mode