Skip to content

Commit

Permalink
Fix entity jq parsing (#54)
Browse files Browse the repository at this point in the history
* fixed entity jq parsing
  • Loading branch information
yairsimantov20 authored Aug 8, 2023
1 parent 7621eae commit bf0c21b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 30 deletions.
1 change: 1 addition & 0 deletions changelog/bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed an issue that caused the jq `None` values for relations to become a string with the value `"None"` instead of being interpreted as `null` in JSON
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ def order_by_entities_dependencies(entities: list[Entity]) -> list[Entity]:
entities_map[node(entity)] = entity

for entity in entities:
relation_target_ids = [
identifier
for relation in entity.relations.values()
for identifier in relation
]
relation_target_ids: list[str] = sum(
[
identifiers if isinstance(identifiers, list) else [identifiers]
for identifiers in entity.relations.values()
if identifiers is not None
],
[],
)
related_entities = [
related for related in entities if related.identifier in relation_target_ids
]
Expand Down
29 changes: 5 additions & 24 deletions port_ocean/core/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Type, TypeVar
from typing import Any, TypeVar

from pydantic import BaseModel
from pydantic.fields import Field
Expand All @@ -7,32 +7,13 @@


class Entity(BaseModel):
identifier: str
blueprint: str
title: str | None
team: str | list[str] = []
identifier: Any
blueprint: Any
title: Any
team: str | None | list[Any] = []
properties: dict[str, Any] = {}
relations: dict[str, Any] = {}

@classmethod
def parse_obj(cls: Type["Model"], obj: dict[Any, Any]) -> "Model":
obj["identifier"] = str(obj.get("identifier"))
obj["blueprint"] = str(obj.get("blueprint"))
if obj.get("team"):
team = obj.get("team")
obj["team"] = (
[str(item) for item in team]
if isinstance(team, list)
else str(obj.get("team"))
)

for key, value in obj.get("relations", {}).items():
if isinstance(value, list):
obj["relations"][key] = [str(item) for item in value]
else:
obj["relations"][key] = str(value)
return super(Entity, cls).parse_obj(obj)


class BlueprintRelation(BaseModel):
many: bool
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 = "port-ocean"
version = "0.1.3"
version = "0.1.4dev4"
description = "Port Ocean is a CLI tool for managing your Port projects."
readme = "README.md"
homepage = "https://app.getport.io"
Expand Down

0 comments on commit bf0c21b

Please sign in to comment.