Skip to content

Commit

Permalink
remove InAssetSubtree from time series filters (#1743)
Browse files Browse the repository at this point in the history
  • Loading branch information
haakonvt authored Apr 30, 2024
1 parent e0770ca commit 34e7af2
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 123 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.40.2] - 2024-04-30
### Fixed
- `InAssetSubtree` is no longer (mistakenly) accepted as a time series filter.

## [7.40.1] - 2024-04-30
### Fixed
- Deleting multiple Datapoint Subscriptions now work as expected.
Expand Down
18 changes: 2 additions & 16 deletions cognite/client/_api/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
AssetWrite,
SortableAssetProperty,
)
from cognite.client.data_classes.filters import Filter, _validate_filter
from cognite.client.data_classes.filters import _BASIC_FILTERS, Filter, _validate_filter
from cognite.client.exceptions import CogniteAPIError
from cognite.client.utils._auxiliary import split_into_chunks, split_into_n_parts
from cognite.client.utils._concurrency import ConcurrencySettings, classify_error, execute_tasks
Expand Down Expand Up @@ -81,21 +81,7 @@
Tuple[str, Literal["asc", "desc"], Literal["auto", "first", "last"]],
]

_FILTERS_SUPPORTED: frozenset[type[Filter]] = frozenset(
{
filters.And,
filters.Or,
filters.Not,
filters.In,
filters.Equals,
filters.Exists,
filters.Range,
filters.Prefix,
filters.ContainsAny,
filters.ContainsAll,
filters.Search,
}
)
_FILTERS_SUPPORTED: frozenset[type[Filter]] = _BASIC_FILTERS | {filters.Search}


class AssetsAPI(APIClient):
Expand Down
23 changes: 4 additions & 19 deletions cognite/client/_api/data_modeling/instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
SourceSelector,
)
from cognite.client.data_classes.data_modeling.views import View
from cognite.client.data_classes.filters import Filter, _validate_filter
from cognite.client.data_classes.filters import _BASIC_FILTERS, Filter, _validate_filter
from cognite.client.utils._auxiliary import load_yaml_or_json
from cognite.client.utils._concurrency import ConcurrencySettings
from cognite.client.utils._identifier import DataModelingIdentifierSequence
Expand All @@ -75,23 +75,8 @@
if TYPE_CHECKING:
from cognite.client import CogniteClient

_DATA_MODELING_SUPPORTED_FILTERS: frozenset[type[Filter]] = frozenset(
{
filters.And,
filters.Or,
filters.Not,
filters.In,
filters.Equals,
filters.Exists,
filters.Range,
filters.Prefix,
filters.ContainsAny,
filters.ContainsAll,
filters.Nested,
filters.HasData,
filters.MatchAll,
filters.Overlaps,
}
_FILTERS_SUPPORTED: frozenset[type[Filter]] = _BASIC_FILTERS.union(
{filters.Nested, filters.HasData, filters.MatchAll, filters.Overlaps}
)

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -1197,7 +1182,7 @@ def list(
)

def _validate_filter(self, filter: Filter | dict[str, Any] | None) -> None:
_validate_filter(filter, _DATA_MODELING_SUPPORTED_FILTERS, type(self).__name__)
_validate_filter(filter, _FILTERS_SUPPORTED, type(self).__name__)

@staticmethod
def _merge_space_into_filter(
Expand Down
24 changes: 4 additions & 20 deletions cognite/client/_api/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,13 @@
SourceFileProperty,
TemporaryLink,
)
from cognite.client.data_classes.filters import Filter, _validate_filter
from cognite.client.data_classes.filters import _BASIC_FILTERS, Filter, _validate_filter

if TYPE_CHECKING:
from cognite.client import ClientConfig, CogniteClient

_DOCUMENTS_SUPPORTED_FILTERS: frozenset[type[Filter]] = frozenset(
{
filters.And,
filters.Or,
filters.Not,
filters.In,
filters.Equals,
filters.Exists,
filters.Range,
filters.Prefix,
filters.ContainsAny,
filters.ContainsAll,
filters.GeoJSONIntersects,
filters.GeoJSONDisjoint,
filters.GeoJSONWithin,
filters.InAssetSubtree,
filters.Search,
}
_FILTERS_SUPPORTED: frozenset[type[Filter]] = _BASIC_FILTERS.union(
{filters.InAssetSubtree, filters.Search, filters.GeoJSONIntersects, filters.GeoJSONDisjoint, filters.GeoJSONWithin}
)


Expand Down Expand Up @@ -701,4 +685,4 @@ def list(
)

def _validate_filter(self, filter: Filter | dict[str, Any] | None) -> None:
_validate_filter(filter, _DOCUMENTS_SUPPORTED_FILTERS, type(self).__name__)
_validate_filter(filter, _FILTERS_SUPPORTED, type(self).__name__)
18 changes: 2 additions & 16 deletions cognite/client/_api/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
)
from cognite.client.data_classes.aggregations import AggregationFilter, UniqueResultList
from cognite.client.data_classes.events import EventPropertyLike, EventSort, EventWrite, SortableEventProperty
from cognite.client.data_classes.filters import Filter, _validate_filter
from cognite.client.data_classes.filters import _BASIC_FILTERS, Filter, _validate_filter
from cognite.client.utils._identifier import IdentifierSequence
from cognite.client.utils._validation import prepare_filter_sort, process_asset_subtree_ids, process_data_set_ids
from cognite.client.utils.useful_types import SequenceNotStr
Expand All @@ -32,21 +32,7 @@
Tuple[str, Literal["asc", "desc"], Literal["auto", "first", "last"]],
]

_FILTERS_SUPPORTED: frozenset[type[Filter]] = frozenset(
{
filters.And,
filters.Or,
filters.Not,
filters.In,
filters.Equals,
filters.Exists,
filters.Range,
filters.Prefix,
filters.ContainsAny,
filters.ContainsAll,
filters.Search,
}
)
_FILTERS_SUPPORTED: frozenset[type[Filter]] = _BASIC_FILTERS | {filters.Search}


class EventsAPI(APIClient):
Expand Down
18 changes: 2 additions & 16 deletions cognite/client/_api/sequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
filters,
)
from cognite.client.data_classes.aggregations import AggregationFilter, CountAggregate, UniqueResultList
from cognite.client.data_classes.filters import Filter, _validate_filter
from cognite.client.data_classes.filters import _BASIC_FILTERS, Filter, _validate_filter
from cognite.client.data_classes.sequences import (
SequenceCore,
SequenceProperty,
Expand Down Expand Up @@ -53,21 +53,7 @@
Tuple[str, Literal["asc", "desc"], Literal["auto", "first", "last"]],
]

_FILTERS_SUPPORTED: frozenset[type[Filter]] = frozenset(
{
filters.And,
filters.Or,
filters.Not,
filters.In,
filters.Equals,
filters.Exists,
filters.Range,
filters.Prefix,
filters.ContainsAny,
filters.ContainsAll,
filters.Search,
}
)
_FILTERS_SUPPORTED: frozenset[type[Filter]] = _BASIC_FILTERS | {filters.Search}


class SequencesAPI(APIClient):
Expand Down
19 changes: 2 additions & 17 deletions cognite/client/_api/time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
filters,
)
from cognite.client.data_classes.aggregations import AggregationFilter, CountAggregate, UniqueResultList
from cognite.client.data_classes.filters import Filter, _validate_filter
from cognite.client.data_classes.filters import _BASIC_FILTERS, Filter, _validate_filter
from cognite.client.data_classes.time_series import (
SortableTimeSeriesProperty,
TimeSeriesProperty,
Expand All @@ -40,22 +40,7 @@
Tuple[str, Literal["asc", "desc"], Literal["auto", "first", "last"]],
]

_FILTERS_SUPPORTED: frozenset[type[Filter]] = frozenset(
{
filters.And,
filters.Or,
filters.Not,
filters.In,
filters.Equals,
filters.Exists,
filters.Range,
filters.Prefix,
filters.ContainsAny,
filters.ContainsAll,
filters.InAssetSubtree,
filters.Search,
}
)
_FILTERS_SUPPORTED: frozenset[type[Filter]] = _BASIC_FILTERS | {filters.Search}


class TimeSeriesAPI(APIClient):
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.40.1"
__version__ = "7.40.2"
__api_subversion__ = "20230101"
20 changes: 3 additions & 17 deletions cognite/client/data_classes/datapoints_subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from typing_extensions import Self, TypeAlias

from cognite.client.data_classes import Datapoints, filters
from cognite.client.data_classes import Datapoints
from cognite.client.data_classes._base import (
CogniteListUpdate,
CognitePrimitiveUpdate,
Expand All @@ -21,6 +21,7 @@
WriteableCogniteResource,
WriteableCogniteResourceList,
)
from cognite.client.data_classes.filters import _BASIC_FILTERS as _FILTERS_SUPPORTED
from cognite.client.data_classes.filters import Filter, _validate_filter
from cognite.client.utils import _json
from cognite.client.utils._auxiliary import exactly_one_is_not_none
Expand All @@ -30,21 +31,6 @@

ExternalId: TypeAlias = str

_DATAPOINT_SUBSCRIPTION_SUPPORTED_FILTERS: frozenset[type[Filter]] = frozenset(
{
filters.And,
filters.Or,
filters.Not,
filters.In,
filters.Equals,
filters.Exists,
filters.Range,
filters.Prefix,
filters.ContainsAny,
filters.ContainsAll,
}
)


class DatapointSubscriptionCore(WriteableCogniteResource["DataPointSubscriptionWrite"], ABC):
def __init__(
Expand Down Expand Up @@ -157,7 +143,7 @@ def __init__(
) -> None:
if not exactly_one_is_not_none(time_series_ids, filter):
raise ValueError("Exactly one of time_series_ids and filter must be given")
_validate_filter(filter, _DATAPOINT_SUBSCRIPTION_SUPPORTED_FILTERS, "DataPointSubscriptions")
_validate_filter(filter, _FILTERS_SUPPORTED, "DataPointSubscriptions")
super().__init__(external_id, partition_count, filter, name, description, data_set_id)
self.time_series_ids = time_series_ids

Expand Down
5 changes: 5 additions & 0 deletions cognite/client/data_classes/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,11 @@ class Search(FilterWithPropertyAndValue):
_filter_name = "search"


_BASIC_FILTERS: frozenset[type[Filter]] = frozenset(
{And, Or, Not, In, Equals, Exists, Range, Prefix, ContainsAny, ContainsAll}
)


# ######################################################### #
# Custom filters below (custom meaning 'no API equivalent') #
# ######################################################### #
Expand Down
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.40.1"
version = "7.40.2"
description = "Cognite Python SDK"
readme = "README.md"
documentation = "https://cognite-sdk-python.readthedocs-hosted.com"
Expand Down

0 comments on commit 34e7af2

Please sign in to comment.