diff --git a/taipy/core/data/data_node.py b/taipy/core/data/data_node.py index afd5480247..c1c4094090 100644 --- a/taipy/core/data/data_node.py +++ b/taipy/core/data/data_node.py @@ -147,8 +147,6 @@ def __init__( self._edits: List[Edit] = edits or [] self._properties: _Properties = _Properties(self, **kwargs) - dn_cfg = Config.data_nodes.get(self._config_id, None) - self._ranks: Dict[str, int] = dn_cfg._ranks if dn_cfg else {} def __eq__(self, other) -> bool: """Check if two data nodes are equal.""" @@ -572,23 +570,28 @@ def get_last_edit(self) -> Optional[Edit]: """ return self._edits[-1] if self._edits else None - def get_rank(self) -> int: - """Get the rank of this data node regarding to its scenario owner + def _get_rank(self, scenario_config_id: str) -> int: + """Get the data node rank for given scenario config. + + The rank corresponds to the order of appearance of the data nodes in a scenario config DAG. + + Arguments: + scenario_config_id (str): The identifier of the scenario config used to + get the data node rank. Returns: - The int value representing the rank. + The int value representing the rank of the data node config in the scenario config DAG. + If the data node config is not found or has no rank, 0xffff is returned. These cases should never happen. + If the data node config is not part of the scenario config, 0xfffe is returned as an infinite rank. """ - if not self.owner_id: - return 0xfffe - config = Config.data_nodes.get(self.config_id, None) - if not config: - return 0xfffd - - from ... import core as tp - owner = tp.get(self.owner_id) - if not isinstance(owner, tp.Scenario): - return 0xfffc - return config._ranks.get(owner.config_id, 0xfffb) + dn_config = Config.data_nodes.get(self._config_id, None) + if not dn_config: + self._logger.error(f"Data node config `{self.config_id}` for data node `{self.id}` is not found.") + return 0xffff + if not dn_config._ranks: + self._logger.error(f"Data node config `{self.config_id}` for data node `{self.id}` has no rank.") + return 0xffff + return dn_config._ranks.get(scenario_config_id, 0xfffe) @abstractmethod def _read(self): diff --git a/taipy/gui_core/_adapters.py b/taipy/gui_core/_adapters.py index 0221df2c28..728958230e 100644 --- a/taipy/gui_core/_adapters.py +++ b/taipy/gui_core/_adapters.py @@ -567,7 +567,7 @@ class _GuiCoreDatanodeProperties(_GuiCoreProperties): _GuiCorePropDesc(DataNodeFilter("Last edit date", datetime, "last_edit_date"), for_sort=True), _GuiCorePropDesc(DataNodeFilter("Expiration date", datetime, "expiration_date"), extended=True, for_sort=True), _GuiCorePropDesc(DataNodeFilter("Expired", bool, "is_expired"), extended=True), - _GuiCorePropDesc(DataNodeFilter("Rank", int, "get_rank()"), for_sort=True), + _GuiCorePropDesc(DataNodeFilter("Rank", int, "_get_rank()"), for_sort=True), ] __DN_VALIDITY = None diff --git a/tests/core/data/test_data_node.py b/tests/core/data/test_data_node.py index 649fe3cea3..414f4c71f9 100644 --- a/tests/core/data/test_data_node.py +++ b/tests/core/data/test_data_node.py @@ -74,7 +74,6 @@ def test_create_with_default_values(self): assert dn.job_ids == [] assert not dn.is_ready_for_reading assert len(dn.properties) == 0 - assert len(dn._ranks) == 0 def test_create_with_ranks(self): # Test _rank is propagated from the config @@ -92,10 +91,9 @@ def test_create_with_ranks(self): assert dn.job_ids == [] assert not dn.is_ready_for_reading assert len(dn.properties) == 0 - assert len(dn._ranks) == 3 - assert dn._ranks["A"] == 1 - assert dn._ranks["B"] == 2 - assert dn._ranks["C"] == 0 + assert dn._get_rank("A") == 1 + assert dn._get_rank("B") == 2 + assert dn._get_rank("C") == 0 def test_is_up_to_date_when_not_written(self): dn_confg_1 = Config.configure_in_memory_data_node("dn_1", default_data="a") @@ -137,7 +135,6 @@ def test_create(self): assert dn.is_ready_for_reading assert len(dn.properties) == 2 assert dn.properties == {"prop": "erty", "name": "a name"} - assert len(dn._ranks) == 0 with pytest.raises(InvalidConfigurationId): DataNode("foo bar")