Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion cognite/client/_api/functions/schedules.py
Comment thread
haakonvt marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,17 @@ async def list(
limit = 10_000

_ensure_at_most_one_id_given(function_id, function_external_id)

if isinstance(function_external_id, str):
function = await self._cognite_client.functions.retrieve(external_id=function_external_id)
if function is None:
# NOTE: Unknown function ID also returns an empty list
return FunctionSchedulesList([])
function_id = function.id

filter = FunctionSchedulesFilter(
name=name,
function_id=function_id,
function_external_id=function_external_id,
created_time=created_time,
cron_expression=cron_expression,
).dump(camel_case=True)
Expand Down
2 changes: 1 addition & 1 deletion cognite/client/_sync_api/functions/schedules.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ all = [

[dependency-groups]
dev = [
"pytest >=7",
"pytest >=9",
"pytest-cov (>=3, <7)", # pytest-cov 7+ has issues with coverage measurement
"coverage (>=7, <7.11)", # 7.11+ has issues with editable installs in parallel test execution
"pytest-rerunfailures >=10",
Expand Down
12 changes: 11 additions & 1 deletion tests/tests_integration/test_api/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ def test_call_function_with_oneshot(self, cognite_client: CogniteClient, a_funct


class TestFunctionSchedulesAPI:
def test_create_retrieve_delete(self, cognite_client: CogniteClient, a_function: Function) -> None:
def test_create_retrieve_delete(
self, cognite_client: CogniteClient, a_function: Function, subtests: pytest.Subtests
) -> None:
Comment thread
MortGron marked this conversation as resolved.
my_schedule = FunctionScheduleWrite(
name="python-sdk-test-schedule",
cron_expression="0 0 1 1 *",
Expand All @@ -178,6 +180,14 @@ def test_create_retrieve_delete(self, cognite_client: CogniteClient, a_function:
assert isinstance(retrieved, FunctionSchedule)
assert retrieved.dump() == created.dump()

with subtests.test(msg="List with function external ID"):
schedules = cognite_client.functions.schedules.list(function_external_id=a_function.external_id)
assert any(s.id == created.id for s in schedules)

with subtests.test(msg="List with unknown function external ID"):
schedules = cognite_client.functions.schedules.list(function_external_id="unknown_external_id")
assert len(schedules) == 0
Comment thread
MortGron marked this conversation as resolved.

cognite_client.functions.schedules.delete(id=created.id)
finally:
if created:
Expand Down
Loading