Skip to content

Commit

Permalink
Fix pydantic failure on jq (#19)
Browse files Browse the repository at this point in the history
* fixed pydantic failure

* encoding identifier
  • Loading branch information
yairsimantov20 authored Jul 20, 2023
1 parent 13c36ac commit d9bc4a8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
4 changes: 3 additions & 1 deletion port_ocean/clients/port/mixins/entities.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from urllib.parse import quote_plus

import httpx
from loguru import logger

Expand Down Expand Up @@ -59,7 +61,7 @@ async def delete_entity(
f"Delete entity: {entity.identifier} of blueprint: {entity.blueprint}"
)
response = await self.client.delete(
f"{self.auth.api_url}/blueprints/{entity.blueprint}/entities/{entity.identifier}",
f"{self.auth.api_url}/blueprints/{entity.blueprint}/entities/{quote_plus(entity.identifier)}",
headers=await self.auth.headers(user_agent_type),
params={
"delete_dependents": str(
Expand Down
23 changes: 22 additions & 1 deletion port_ocean/core/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from typing import Any
from typing import Any, Type, TypeVar

from pydantic import BaseModel
from pydantic.fields import Field

Model = TypeVar("Model", bound="BaseModel")


class Entity(BaseModel):
identifier: str
Expand All @@ -12,6 +14,25 @@ class Entity(BaseModel):
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
11 changes: 7 additions & 4 deletions port_ocean/port_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,12 @@ async def _initialize_defaults(
def initialize_defaults(
config_class: Type[PortAppConfig], integration_config: IntegrationConfiguration
) -> None:
asyncio.new_event_loop().run_until_complete(
_initialize_defaults(config_class, integration_config)
)
try:
asyncio.new_event_loop().run_until_complete(
_initialize_defaults(config_class, integration_config)
)
except Exception as e:
logger.debug(f"Failed to initialize defaults, skipping... Error: {e}")


def get_port_integration_defaults(
Expand Down Expand Up @@ -221,6 +224,6 @@ def get_port_integration_defaults(
actions=default_jsons.get("actions", []),
scorecards=default_jsons.get("scorecards", []),
port_app_config=port_app_config_class(
**default_jsons.get("port_app_config", {})
**default_jsons.get("port-app-config", {})
),
)

0 comments on commit d9bc4a8

Please sign in to comment.