Skip to content

Commit

Permalink
chore: bump to pydantic 2.3.0 (#718)
Browse files Browse the repository at this point in the history
# Companion PR

- Substra/substra#375 (main)
- Substra/substrafl#159
- Substra/substra-tests#272
- #718

---------

Signed-off-by: ThibaultFy <50656860+ThibaultFy@users.noreply.github.com>
  • Loading branch information
ThibaultFy authored Sep 8, 2023
1 parent 9a7259d commit 2e7446f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,7 @@ backend/node/nodes/*
# charts tmp files
charts/substra-backend/tmpcharts/*
skaffold-overrides.yaml

# Mac OS

.DS_Store
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## Changed

- Update to pydantic 2.3.0 ([#718](https://github.com/Substra/substra-backend/pull/718))

## [0.41.0](https://github.com/Substra/substra-backend/releases/tag/0.41.0) 2023-09-07

### Added
Expand Down Expand Up @@ -34,7 +38,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Remove pagination on `get_performances` to remove limitation on 1000 first points ([#690](https://github.com/Substra/substra-backend/pull/690))
- - Update or create the step profiling, instead of raising an error if already exists ([#691](https://github.com/Substra/substra-backend/pull/691))
- Update or create the step profiling, instead of raising an error if already exists ([#691](https://github.com/Substra/substra-backend/pull/691))

### Added

Expand Down
10 changes: 5 additions & 5 deletions backend/orchestrator/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ def from_grpc(cls, o: computetask_pb2.ComputeTaskOutput) -> ComputeTaskOutput:

class ComputeTaskInput(pydantic.BaseModel):
identifier: str
asset_key: Optional[str]
parent_task_key: Optional[str]
parent_task_output_identifier: Optional[str]
asset_key: Optional[str] = None
parent_task_key: Optional[str] = None
parent_task_output_identifier: Optional[str] = None

@classmethod
def from_grpc(cls, i: computetask_pb2.ComputeTaskInput) -> ComputeTaskInput:
Expand Down Expand Up @@ -299,8 +299,8 @@ def __repr__(self) -> str:
class ComputePlan(_Base):
key: str
tag: str
cancelation_date: Optional[datetime.datetime]
failure_date: Optional[datetime.datetime]
cancelation_date: Optional[datetime.datetime] = None
failure_date: Optional[datetime.datetime] = None

@classmethod
def from_grpc(cls, compute_plan: computeplan_pb2.ComputePlan) -> ComputePlan:
Expand Down
2 changes: 1 addition & 1 deletion backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ grpcio-tools==1.57.0
minio==7.1.14
django-prometheus==2.3.1
django-filter==23.2
pydantic==1.10.1
pydantic==2.3.0
redis==4.5.4
mozilla-django-oidc==3.0.0
# Dependencies used in local dev mode
Expand Down
4 changes: 2 additions & 2 deletions backend/substrapp/tasks/tasks_compute_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def on_failure(

def split_args(self, celery_args: tuple) -> tuple[str, orchestrator.ComputeTask]:
channel_name = celery_args[0]
task = orchestrator.ComputeTask.parse_raw(celery_args[1])
task = orchestrator.ComputeTask.model_validate_json(celery_args[1])
return channel_name, task


Expand Down Expand Up @@ -178,7 +178,7 @@ def queue_compute_task(channel_name: str, task: orchestrator.ComputeTask) -> Non
# see http://docs.celeryproject.org/en/latest/userguide/configuration.html#task-reject-on-worker-lost
# and https://github.com/celery/celery/issues/5106
def compute_task(self: ComputeTask, channel_name: str, serialized_task: str, compute_plan_key: str) -> None:
task = orchestrator.ComputeTask.parse_raw(serialized_task)
task = orchestrator.ComputeTask.model_validate_json(serialized_task)
datastore = get_datastore(channel=channel_name)
try:
_run(self, channel_name, task, compute_plan_key, datastore)
Expand Down
16 changes: 8 additions & 8 deletions backend/substrapp/tests/tasks/test_compute_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class FakeDirectories:

mock_ctx_from_task = mocker.patch("substrapp.tasks.tasks_compute_task.Context.from_task", return_value=ctx)

compute_task(CHANNEL, task.json(), None)
compute_task(CHANNEL, task.model_dump_json(), None)

assert mock_raise_if_not_runnable.call_count == 2
mock_ctx_from_task.assert_called_once()
Expand All @@ -79,26 +79,26 @@ class FakeDirectories:

saver.save_outputs.side_effect = error
with pytest.raises(errors.CeleryRetryError) as excinfo:
compute_task(CHANNEL, task.json(), None)
compute_task(CHANNEL, task.model_dump_json(), None)
assert str(excinfo.value.__cause__.details) == "OE0000"

# test compute error
mock_execute_compute_task.side_effect = Exception("Test")
with pytest.raises(errors.CeleryRetryError) as excinfo:
compute_task(CHANNEL, task.json(), None)
compute_task(CHANNEL, task.model_dump_json(), None)

assert str(excinfo.value.__cause__) == "Test"

# test not enough space on disk error
mock_execute_compute_task.side_effect = OSError(errno.ENOSPC, "No space left on device")
with pytest.raises(errors.CeleryRetryError) as excinfo:
compute_task(CHANNEL, task.json(), None)
compute_task(CHANNEL, task.model_dump_json(), None)
assert "No space left on device" in str(excinfo.value.__cause__)

# test other OS error
mock_execute_compute_task.side_effect = OSError(errno.EACCES, "Dummy error")
with pytest.raises(errors.CeleryRetryError) as excinfo:
compute_task(CHANNEL, task.json(), None)
compute_task(CHANNEL, task.model_dump_json(), None)
assert "Dummy error" in str(excinfo.value.__cause__)


Expand Down Expand Up @@ -156,7 +156,7 @@ def basic_retry(exc, **retry_kwargs):
mock_execute_compute_task.side_effect = Exception(exception_message)

with pytest.raises(errors.CeleryRetryError) as excinfo:
compute_task(CHANNEL, task.json(), None)
compute_task(CHANNEL, task.model_dump_json(), None)

assert str(excinfo.value.__cause__) == exception_message
mock_retry.assert_called_once()
Expand All @@ -165,7 +165,7 @@ def basic_retry(exc, **retry_kwargs):
mock_execute_compute_task.side_effect = IOError(errno.ENOSPC, "no file left on device")

with pytest.raises(errors.CeleryRetryError) as excinfo:
compute_task(CHANNEL, task.json(), None)
compute_task(CHANNEL, task.model_dump_json(), None)

assert "no file left on device" in str(excinfo.value.__cause__)
assert mock_retry.call_count == 2
Expand All @@ -175,7 +175,7 @@ def basic_retry(exc, **retry_kwargs):
mock_execute_compute_task.side_effect = errors.ExecutionError("python not found", "Error while running command")

with pytest.raises(errors.CeleryNoRetryError) as excinfo:
compute_task(CHANNEL, task.json(), None)
compute_task(CHANNEL, task.model_dump_json(), None)

assert "Error while running command" in str(excinfo.value)
assert mock_retry.call_count == 2
Expand Down

0 comments on commit 2e7446f

Please sign in to comment.