Skip to content

Commit

Permalink
Neat 251 missing warning when detecting raw filter in post validation (
Browse files Browse the repository at this point in the history
…#454)

* added raw filter warning

* bump version/changelog
  • Loading branch information
nikokaoja committed May 14, 2024
1 parent 28eb266 commit eedfda0
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: run-explorer run-tests run-linters build-ui build-python build-docker run-docker compose-up

version="0.77.1"
version="0.77.2"
run-explorer:
@echo "Running explorer API server..."
# open "http://localhost:8000/static/index.html" || true
Expand Down
2 changes: 1 addition & 1 deletion cognite/neat/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.77.1"
__version__ = "0.77.2"
20 changes: 20 additions & 0 deletions cognite/neat/rules/issues/dms.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,26 @@ def dump(self) -> dict[str, Any]:
return output


@dataclass(frozen=True)
class RawFilterAppliedToViewWarning(DMSSchemaWarning):
description = "Raw filter is applied to a view, which is against the neat data modeling lifecycle."
fix = "Do not use raw filter, instead use HasData filter or nodeType filter or change the data model design."
error_name: ClassVar[str] = "RawFilterAppliedToView"
view_id: dm.ViewId

def message(self) -> str:
return (
f"RawFilter applied to the view {self.view_id}."
" The usage of RawFilter is against the neat team recommendations and the neat data modeling lifecycle."
" When opting for raw filter, the user is responsible for any errors that arise in neat."
)

def dump(self) -> dict[str, Any]:
output = super().dump()
output["view_id"] = self.view_id.dump()
return output


@dataclass(frozen=True)
class NodeTypeFilterOnParentViewWarning(DMSSchemaWarning):
description = (
Expand Down
2 changes: 1 addition & 1 deletion cognite/neat/rules/models/dms/_rules_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class DMSViewInput:
description: str | None = None
implements: str | None = None
reference: str | None = None
filter_: Literal["hasData", "nodeType"] | None = None
filter_: Literal["hasData", "nodeType", "rawFilter"] | None = None
in_model: bool = True

@classmethod
Expand Down
11 changes: 11 additions & 0 deletions cognite/neat/rules/models/dms/_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from cognite.neat.rules.models._base import ExtensionCategory, SchemaCompleteness
from cognite.neat.rules.models.data_types import DataType
from cognite.neat.rules.models.entities import ContainerEntity
from cognite.neat.rules.models.wrapped_entities import RawFilter

from ._rules import DMSProperty, DMSRules

Expand All @@ -25,6 +26,7 @@ def __init__(self, rules: DMSRules):
self.issue_list = IssueList()

def validate(self) -> IssueList:
self._validate_best_practices()
self._consistent_container_properties()
self._referenced_views_and_containers_are_existing()
self._validate_extension()
Expand Down Expand Up @@ -241,6 +243,15 @@ def _validate_performance(self) -> None:
)
)

def _validate_best_practices(self) -> None:
for view in self.views:
if view.filter_ and isinstance(view.filter_, RawFilter):
self.issue_list.append(
issues.dms.RawFilterAppliedToViewWarning(
view_id=view.view.as_id(),
)
)

@staticmethod
def _changed_attributes_and_properties(
new_dumped: dict[str, Any], existing_dumped: dict[str, Any]
Expand Down
7 changes: 6 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ Changes are grouped as follows:
- `Fixed` for any bug fixes.
- `Security` in case of vulnerabilities.

## [0.77.2] - 14-05-24
### Added
- Missing warning when `RawFilter` is used to warn users that the usage of this filter is not recommended.


## [0.77.1] - 14-05-24
### Added
- Support for `RawFilters` allow arbitrary filters to be applied to the data model.
- Support for `RawFilter` allow arbitrary filters to be applied to the data model.


## [0.77.0] - 13-05-24
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cognite-neat"
version = "0.77.1"
version = "0.77.2"
readme = "README.md"
description = "Knowledge graph transformation"
authors = [
Expand Down

0 comments on commit eedfda0

Please sign in to comment.