Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Commit

Permalink
fix: _VersionManager._replace_version_number() should return version_…
Browse files Browse the repository at this point in the history
…number if the version exists but the Config is alternated (#565)
  • Loading branch information
trgiangdo authored Apr 27, 2023
1 parent 3d5c9a3 commit e284869
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/taipy/core/_version/_version_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from taipy.config import Config
from taipy.config._config_comparator import _ConfigComparator
from taipy.config.exceptions.exceptions import InconsistentEnvVariableError
from taipy.logger._taipy_logger import _TaipyLogger

from .._manager._manager import _Manager
Expand Down Expand Up @@ -177,8 +178,12 @@ def _replace_version_number(cls, version_number):
return cls._get_production_version()
if version_number in cls.__ALL_VERSION:
return ""
if version := cls._get(version_number):
return version.id

try:
if version := cls._get(version_number):
return version.id
except InconsistentEnvVariableError: # The version exist but the Config is alternated
return version_number

raise NonExistingVersion(version_number)

Expand Down
32 changes: 32 additions & 0 deletions tests/core/version/test_version_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,38 @@ def test_dev_mode_clean_all_entities_of_the_latest_version():
assert _JobManager._get_all(version_number="foo")


def twice_doppelganger(a):
return a * 2


def test_dev_mode_clean_all_entities_when_config_is_alternated():
data_node_1_config = Config.configure_data_node(
id="d1", storage_type="pickle", default_data="abc", scope=Scope.SCENARIO
)
data_node_2_config = Config.configure_data_node(id="d2", storage_type="csv", default_path="foo.csv")
task_config = Config.configure_task("my_task", twice_doppelganger, data_node_1_config, data_node_2_config)
pipeline_config = Config.configure_pipeline("my_pipeline", task_config)
scenario_config = Config.configure_scenario("my_scenario", pipeline_config, frequency=Frequency.DAILY)

# Create a scenario in development mode with the doppelganger function
with patch("sys.argv", ["prog"]):
core = Core()
core.run()
scenario = _ScenarioManager._create(scenario_config)
_ScenarioManager._submit(scenario)
core.stop()

# Delete the doppelganger function
del globals()["twice_doppelganger"]

# Create a scenario in development mode with another function
scenario_config = config_scenario()
with patch("sys.argv", ["prog"]):
Core().run()
scenario = _ScenarioManager._create(scenario_config)
_ScenarioManager._submit(scenario)


def test_version_number_when_switching_mode():
with patch("sys.argv", ["prog", "--development"]):
Core().run()
Expand Down

0 comments on commit e284869

Please sign in to comment.