Skip to content

Commit

Permalink
[CDF-23047] Mutating function schedule (#2003)
Browse files Browse the repository at this point in the history
  • Loading branch information
doctrino authored Nov 1, 2024
1 parent c77381d commit 0941557
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ Changes are grouped as follows
- `Fixed` for any bug fixes.
- `Security` in case of vulnerabilities.

## [7.64.5] - 2024-11-01
### Fixed
- The `client.functions.schedules.create` method no longer mutates the input `FunctionScheduleWrite` object.

## [7.64.4] - 2024-11-01
### Fixed
- Data Workflows: apply more robust path parameter encoding.
Expand Down
3 changes: 2 additions & 1 deletion cognite/client/_api/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,8 @@ def create(
raise ValueError("cron_expression must be specified when creating a new schedule.")
item = FunctionScheduleWrite(name, cron_expression, function_id, function_external_id, description, data)
else:
item = name
# We serialize the object as we mutate `item` using the result from _get_function_internal_id.
item = FunctionScheduleWrite._load(name.dump())
identifier = _get_function_identifier(item.function_id, item.function_external_id)
if item.function_id is None:
item.function_id = _get_function_internal_id(self._cognite_client, identifier)
Expand Down
2 changes: 1 addition & 1 deletion cognite/client/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import annotations

__version__ = "7.64.4"
__version__ = "7.64.5"
__api_subversion__ = "20230101"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "cognite-sdk"

version = "7.64.4"
version = "7.64.5"
description = "Cognite Python SDK"
readme = "README.md"
documentation = "https://cognite-sdk-python.readthedocs-hosted.com"
Expand Down
10 changes: 9 additions & 1 deletion tests/tests_integration/test_api/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,20 @@ def test_create_retrieve_delete(self, cognite_client: CogniteClient, a_function:
function_external_id=a_function.external_id,
data={"key": "value"},
)
original_schedule = FunctionScheduleWrite._load(my_schedule.dump())

created: FunctionSchedule | None = None
try:
created = cognite_client.functions.schedules.create(my_schedule)

assert created.as_write().dump() == my_schedule.dump()
created_dump = created.as_write().dump()
created_dump.pop("functionId")
my_dump = my_schedule.dump()
my_dump.pop("functionExternalId")

assert created_dump == my_dump
# This check is to ensure that the original schedule is not modified
assert my_schedule.dump() == original_schedule.dump()

retrieved = cognite_client.functions.schedules.retrieve(id=created.id)
assert isinstance(retrieved, FunctionSchedule)
Expand Down

0 comments on commit 0941557

Please sign in to comment.