diff --git a/port_ocean/clients/port/mixins/entities.py b/port_ocean/clients/port/mixins/entities.py index 2194e6e3ba..4bb69edbea 100644 --- a/port_ocean/clients/port/mixins/entities.py +++ b/port_ocean/clients/port/mixins/entities.py @@ -1,3 +1,5 @@ +from urllib.parse import quote_plus + import httpx from loguru import logger @@ -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( diff --git a/port_ocean/core/models.py b/port_ocean/core/models.py index a869e9c4e6..5a73c19cfc 100644 --- a/port_ocean/core/models.py +++ b/port_ocean/core/models.py @@ -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 @@ -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 diff --git a/port_ocean/port_defaults.py b/port_ocean/port_defaults.py index 98a3c84ec3..0a73808166 100644 --- a/port_ocean/port_defaults.py +++ b/port_ocean/port_defaults.py @@ -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( @@ -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", {}) ), )