Avaiga / taipy

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

Protect scenario custom properties to contain key already used #1572

Closed jrobinAV closed 1 week ago

jrobinAV commented 1 month ago

motivation:

When calling scenario.foo, there could be a conflict in the interpretation of foo. It could be:

The purpose of this issue is to avoid conflicts and to ensure property keys are valid python identifiers.

Proposed solution:

Before setting a new property, check if the new key is already used as a config id, or a sequence name. If so raise a dedicate error.

The solution consists of defining two new methods in the Scenario class:

Expected behavior

The following test should pass:

def test_get_set_property_to_scenario():
    dn_cfg = Config.configure_data_node("bar")
    s_cfg = Config.configure_scenario("foo", additional_data_node_configs=[dn_cfg], properties={"key": "value"})
    scenario = taipy.create_scenario(s_cfg)

    assert scenario.properties == {"key": "value"}
    assert scenario.key == "value"

    scenario.properties["new_key"] = "new_value"
    scenario.another_key = "another_value"

    assert scenario.key == "value"
    assert scenario.new_key == "new_value"
    assert scenario.another_key == "another_value"
    assert scenario.properties == {"key": "value", "new_key": "new_value", "another_key": "another_value"}

    with pytest.raises(PropertyKeyAlreadyUsed):
        scenario.bar = "KeyAlreadyUsed"

    with pytest.raises(PropertyKeyAlreadyUsed):
        scenario.properties["bar"] = "KeyAlreadyUsed"

Acceptance criteria

github-actions[bot] commented 3 weeks ago

This issue has been labelled as "🥶Waiting for contributor" because it has been inactive for more than 14 days. If you would like to continue working on this issue, please add another comment or create a PR that links to this issue. If a PR has already been created which refers to this issue, then you should explicitly mention this issue in the relevant PR. Otherwise, you will be unassigned in 14 days. For more information please refer to the contributing guidelines.

github-actions[bot] commented 1 week ago

This issue has been unassigned automatically because it has been marked as "🥶Waiting for contributor" for more than 14 days with no activity.