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

Commit

Permalink
Fix/#366 hot fix (#368)
Browse files Browse the repository at this point in the history
* fix #366 update last_edit_date when a job fails or is abandoned
* change version to 2.0.4
  • Loading branch information
jrobinAV authored Nov 23, 2022
1 parent e4a97df commit 7c70773
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 37 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
test_suite="tests",
tests_require=test_requirements,
url="https://github.com/avaiga/taipy-core",
version="2.0.3",
version="2.0.4",
zip_safe=False,
extras_require=extras_require,
)
2 changes: 1 addition & 1 deletion src/taipy/core/_scheduler/_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def _unlock_edit_on_outputs(jobs: Union[Job, List[Job], Set[Job]]):
jobs = [jobs] if isinstance(jobs, Job) else jobs
for job in jobs:
for dn in job.task.output.values():
dn.unlock_edit(at=dn.last_edit_date)
dn.unlock_edit()

@classmethod
def _on_status_change(cls, job: Job):
Expand Down
5 changes: 3 additions & 2 deletions src/taipy/core/data/abstract_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@

import pandas as pd
from sqlalchemy import create_engine, text

from taipy.config.common.scope import Scope

from .data_node import DataNode
from ..common.alias import DataNodeId, JobId
from ..exceptions.exceptions import InvalidExposedType, MissingRequiredProperty, UnknownDatabaseEngine
from .data_node import DataNode


class AbstractSQLDataNode(DataNode):
Expand Down Expand Up @@ -77,7 +78,7 @@ def __init__(
**properties,
)
if not self._last_edit_date:
self.unlock_edit()
self.last_edit_date = datetime.now() # type: ignore

def __engine(self):
return self.__create_engine(
Expand Down
2 changes: 1 addition & 1 deletion src/taipy/core/data/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def __init__(
**properties,
)
if not self._last_edit_date and isfile(self._path):
self.unlock_edit()
self.last_edit_date = datetime.now() # type: ignore

@classmethod
def storage_type(cls) -> str:
Expand Down
20 changes: 8 additions & 12 deletions src/taipy/core/data/data_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from ..common._reload import _reload, _self_reload, _self_setter
from ..common._warnings import _warn_deprecated
from ..common.alias import DataNodeId, JobId
from ..config.data_node_config import DataNodeConfig
from ..exceptions.exceptions import NoData
from ._filter import _FilterDataNode
from .operator import JoinOperator, Operator
Expand Down Expand Up @@ -270,7 +269,10 @@ def write(self, data, job_id: Optional[JobId] = None):
from ._data_manager_factory import _DataManagerFactory

self._write(data)
self.unlock_edit(job_id=job_id)
self.last_edit_date = datetime.now() # type: ignore
if job_id:
self._job_ids.append(job_id)
self.unlock_edit()
_DataManagerFactory._build_manager()._set(self)

def lock_edit(self):
Expand All @@ -291,26 +293,20 @@ def lock_edition(self):
def unlock_edit(self, at: datetime = None, job_id: JobId = None):
"""Unlocks the edit of the data node.
The _last_edit_date_ is updated.
Parameters:
at (datetime): The optional datetime of the last modification.
If no _at_ datetime is provided, the current datetime is used.
job_id (JobId^): An optional identifier of the writer.
at (datetime): Deprecated.
job_id (JobId^): Deprecated.
Note:
The data node can be locked with the method `(DataNode.)lock_edit()^`.
"""
self.last_edit_date = at or datetime.now() # type: ignore
self.edit_in_progress = False # type: ignore
if job_id:
self._job_ids.append(job_id)

def unlock_edition(self, at: datetime = None, job_id: JobId = None):
"""
Deprecated. Use unlock_edit instead.
Deprecated. Use (DataNode.)unlock_edit()^` instead.
"""
_warn_deprecated("unlock_edition", suggest="unlock_edit")
self.unlock_edit(at, job_id)
self.unlock_edit()

def filter(self, operators: Union[List, Tuple], join_operator=JoinOperator.AND):
"""Read the data referenced by the data node, appying a filter.
Expand Down
2 changes: 1 addition & 1 deletion src/taipy/core/data/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def __init__(
)

if not self._last_edit_date and isfile(self._path):
self.unlock_edit()
self.last_edit_date = datetime.now() # type: ignore

@property # type: ignore
@_self_reload(DataNode._MANAGER_NAME)
Expand Down
2 changes: 1 addition & 1 deletion src/taipy/core/data/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __init__(
**properties,
)
if not self._last_edit_date:
self.unlock_edit()
self.last_edit_date = datetime.now()

@classmethod
def storage_type(cls) -> str:
Expand Down
2 changes: 1 addition & 1 deletion src/taipy/core/data/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def __init__(
self._encoder = self._properties.get(self._ENCODER_KEY, _DefaultJSONEncoder)

if not self._last_edit_date and isfile(self._path): # type: ignore
self.unlock_edit()
self.last_edit_date = datetime.now() # type: ignore

@classmethod
def storage_type(cls) -> str:
Expand Down
2 changes: 1 addition & 1 deletion src/taipy/core/data/pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def __init__(
if self._path is None:
self._path = self.__build_path()
if not self._last_edit_date and os.path.exists(self._path):
self.unlock_edit()
self.last_edit_date = datetime.now() # type: ignore
if default_value is not None and not os.path.exists(self._path):
self.write(default_value)

Expand Down
4 changes: 2 additions & 2 deletions tests/core/data/test_csv_data_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def test_read_without_header(self):

# Create CSVDataNode with numpy exposed_type
csv_data_node_as_numpy = CSVDataNode(
"bar", Scope.PIPELINE, properties={"path": path, "has_header": False, "exposed_type": "numpy"}
"qux", Scope.PIPELINE, properties={"path": path, "has_header": False, "exposed_type": "numpy"}
)
data_numpy = csv_data_node_as_numpy.read()
assert isinstance(data_numpy, np.ndarray)
Expand All @@ -143,7 +143,7 @@ def test_read_without_header(self):

# Create the same CSVDataNode but with custom exposed_type
csv_data_node_as_custom_object = CSVDataNode(
"bar", Scope.PIPELINE, properties={"path": path, "has_header": False, "exposed_type": MyCustomObject}
"quux", Scope.PIPELINE, properties={"path": path, "has_header": False, "exposed_type": MyCustomObject}
)
data_custom = csv_data_node_as_custom_object.read()
assert isinstance(data_custom, list)
Expand Down
28 changes: 14 additions & 14 deletions tests/core/data/test_data_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,27 +164,27 @@ def test_read_write(self):

def test_ready_for_reading(self):
dn = InMemoryDataNode("foo_bar", Scope.CYCLE)
assert dn.last_edition_date is None
assert dn.last_edit_date is None
assert not dn.is_ready_for_reading
assert dn.job_ids == []

dn.lock_edition()
assert dn.last_edition_date is None
dn.lock_edit()
assert dn.last_edit_date is None
assert not dn.is_ready_for_reading
assert dn.job_ids == []

dn.unlock_edition(a_date := datetime.now(), job_id := JobId("a_job_id"))
assert dn.last_edition_date == a_date
assert dn.is_ready_for_reading
assert dn.job_ids == [job_id]
dn.unlock_edit(datetime.now(), JobId("a_job_id"))
assert dn.last_edit_date is None
assert not dn.is_ready_for_reading
assert dn.job_ids == []

dn.lock_edition()
assert dn.last_edition_date == a_date
dn.lock_edit()
assert dn.last_edit_date is None
assert not dn.is_ready_for_reading
assert dn.job_ids == [job_id]
assert dn.job_ids == []

dn.unlock_edition(b_date := datetime.now())
assert dn.last_edition_date == b_date
dn.write("toto", job_id := JobId("a_job_id"))
assert dn.last_edit_date is not None
assert dn.is_ready_for_reading
assert dn.job_ids == [job_id]

Expand Down Expand Up @@ -571,8 +571,8 @@ def test_unlock_edition_deprecated(self):

with pytest.warns(DeprecationWarning):
with mock.patch("src.taipy.core.data.data_node.DataNode.unlock_edit") as unlock_edit:
dn.unlock_edition(d := datetime.now(), None)
unlock_edit.assert_called_once_with(d, None)
dn.unlock_edition(datetime.now(), None)
unlock_edit.assert_called_once_with()

def test_lock_edition_deprecated(self):
dn = FakeDataNode("foo")
Expand Down

0 comments on commit 7c70773

Please sign in to comment.