Avaiga / taipy

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

[🐛 BUG] On_submission_change - submission is completed twice #2152

Open FlorianJacta opened 3 weeks ago

FlorianJacta commented 3 weeks ago

What went wrong? 🤔

The callback is called twice sometimes with the same parameters. It leads to notifying twice the user that the scenario is completed.

How to replicate

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

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

# Configuration of Data Nodes
input_cfg = Config.configure_data_node("input_dn", default_data=21)
output_cfg = Config.configure_data_node("output_dn")

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

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

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

    if submission_status == 'COMPLETED':
        print("COMPLETED")
        print(submittable)
        print(details)
        notify(state, 'success', 'Completed!')
        # Add additional actions here, like updating the GUI or logging the completion.

    elif submission_status == 'FAILED':
        print("FAILED")
        notify(state, 'error', 'FAILED!')
        # Handle failure, like sending notifications or logging the error.

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

    scenario_md = """
<|{scenario_1}|scenario|on_submission_change=notify_from_submissions|>
"""
    Gui(scenario_md).run()

This is what I receive sometimes. The callback is called twice:

[2024-10-25 11:50:04.385][Taipy][INFO] job JOB_double_bd8e666f-5ce5-40ad-8694-af7d02a3faec is completed.
COMPLETED
COMPLETED
<taipy.core.submission.submission.Submission object at 0x000001BAC6CCCE90>
<taipy.core.submission.submission.Submission object at 0x000001BAC6CCD310>
{'submission_status': 'COMPLETED', 'submittable_entity': my_scenario, 'origin_entity_id': 'SCENARIO_my_scenario_6c3d70af-a896-46f8-a0dc-4f17628b29d4', 'origin_entity_type': 'SCENARIO', 'origin_entity_config_id': 'my_scenario', 'creation_date': datetime.datetime(2024, 10, 25, 11, 50, 4, 207191), 'version': '5395d6e1-e5b7-4c2e-a391-7f71d04e8047', 'job_triggered_submission_status_changed': 'JOB_double_bd8e666f-5ce5-40ad-8694-af7d02a3faec'}
{'submission_status': 'COMPLETED', 'submittable_entity': my_scenario}

Expected behavior

This callback should be called once with these parameters

Environment

Taipy 4.0

Steps to Reproduce Issue

  1. A code fragment
  2. And/or configuration files or code
  3. And/or Taipy GUI Markdown or HTML files

Screenshots

DESCRIPTION

Version of Taipy

4.0

Acceptance Criteria

Code of Conduct

toan-quach commented 2 weeks ago

Hmmm I'm running it on the develop branch and it doesn't seem to have this issue image

toan-quach commented 2 weeks ago

But the problem does happen on 4.0! image