Skip to content

Commit

Permalink
[CDF-23143] 🐛 Issue serialization bug (#713)
Browse files Browse the repository at this point in the history
* tests: added failing test

* fix: not serialize generc
  • Loading branch information
doctrino authored Nov 6, 2024
1 parent ea5f629 commit f4a6c4a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
6 changes: 5 additions & 1 deletion cognite/neat/_issues/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ def _get_variables(self) -> tuple[dict[str, str], bool]:
def dump(self) -> dict[str, Any]:
"""Return a dictionary representation of the issue."""
variables = vars(self)
output = {to_camel(key): self._dump_value(value) for key, value in variables.items() if value is not None}
output = {
to_camel(key): self._dump_value(value)
for key, value in variables.items()
if not (value is None or key.startswith("_"))
}
output["NeatIssue"] = type(self).__name__
return output

Expand Down
5 changes: 5 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ Changes are grouped as follows:
- `Fixed` for any bug fixes.
- `Security` in case of vulnerabilities.

## TBD
### Fixed
- Serializing `ResourceNotDefinedError` class no longer raises a `ValueError`. This happens when a `ResourceNotDefinedError`
is found, for example, when calling `neat.verify()`.

## [0.96.4] - 05-11-**2024**
### Fixed
- `neat.to.excel` or `neat.to.yaml` now correctly writes `ViewTypes` and `Edge` that do not have the default
Expand Down
16 changes: 15 additions & 1 deletion tests/tests_unit/test_issues/test_issue_behavior.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import warnings

from cognite.client import data_modeling as dm

from cognite.neat._issues import IssueList
from cognite.neat._issues.errors import ResourceCreationError
from cognite.neat._issues.errors import ResourceCreationError, ResourceNotDefinedError
from cognite.neat._issues.warnings import NeatValueWarning
from cognite.neat._rules.transformers._verification import _catch_issues

Expand All @@ -26,3 +28,15 @@ def test_warning_in_contextmanager(self) -> None:
warnings.warn(my_warning, stacklevel=2)

assert warning_list == IssueList([my_warning])

def test_dump_generic_specified(self) -> None:
my_issue = ResourceNotDefinedError[dm.ViewId](
identifier=dm.ViewId("neat", "SKUKpi", "v1"),
location="View Sheet",
row_number=66,
sheet_name="Properties",
resource_type="view",
)
dumped = my_issue.dump()

assert isinstance(dumped, dict)

0 comments on commit f4a6c4a

Please sign in to comment.