Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix entity jq parsing #54

Merged
merged 5 commits into from
Aug 8, 2023
Merged
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
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] = []
yairsimantov20 marked this conversation as resolved.
Show resolved Hide resolved
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