diff --git a/changelog/PORT-4398.bugfix.md b/changelog/PORT-4398.bugfix.md new file mode 100644 index 0000000000..3e2cc34d04 --- /dev/null +++ b/changelog/PORT-4398.bugfix.md @@ -0,0 +1 @@ +Pass resource config inside event context \ No newline at end of file diff --git a/changelog/PORT-4411.bugfix.md b/changelog/PORT-4411.bugfix.md new file mode 100644 index 0000000000..eabf8faaa1 --- /dev/null +++ b/changelog/PORT-4411.bugfix.md @@ -0,0 +1 @@ +Fix not supporting multiple relations \ No newline at end of file diff --git a/port_ocean/context/event.py b/port_ocean/context/event.py index 2e2857d266..4de3dc7549 100644 --- a/port_ocean/context/event.py +++ b/port_ocean/context/event.py @@ -10,7 +10,10 @@ from port_ocean.utils import get_time if TYPE_CHECKING: - from port_ocean.core.handlers.port_app_config.models import PortAppConfig + from port_ocean.core.handlers.port_app_config.models import ( + PortAppConfig, + ResourceConfig, + ) TriggerType = Literal["manual", "machine", "request"] @@ -25,6 +28,7 @@ class EventType: class EventContext: event_type: str trigger_type: TriggerType = "machine" + resource_config: Optional["ResourceConfig"] = None attributes: dict[str, Any] = field(default_factory=dict) _port_app_config: Optional["PortAppConfig"] = None _parent_event: Optional["EventContext"] = None @@ -76,6 +80,7 @@ def _get_event_context() -> EventContext: async def event_context( event_type: str, trigger_type: TriggerType = "manual", + resource_config: Optional["ResourceConfig"] = None, attributes: dict[str, Any] | None = None, ) -> AsyncIterator[EventContext]: attributes = attributes or {} @@ -86,8 +91,11 @@ async def event_context( EventContext( event_type, trigger_type=trigger_type, + resource_config=resource_config, attributes=attributes, _parent_event=parent, + # inherit port app config from parent event so it can be used in nested events + _port_app_config=parent.port_app_config if parent else None, ) ) @@ -96,6 +104,10 @@ async def event_context( event_trigger_type=event.trigger_type, event_kind=event.event_type, event_id=event.id, + event_parent_id=event.parent_id, + event_resource_kind=event.resource_config.kind + if event.resource_config + else None, ): logger.info("Event started") try: diff --git a/port_ocean/core/integrations/mixins/sync.py b/port_ocean/core/integrations/mixins/sync.py index c5394f6231..3fc1a19569 100644 --- a/port_ocean/core/integrations/mixins/sync.py +++ b/port_ocean/core/integrations/mixins/sync.py @@ -312,11 +312,19 @@ async def sync_raw_all( creation_results: list[tuple[list[Entity], list[Exception]]] = [] for resource in app_config.resources: - creation_results.append( - await self._register_in_batches( - resource, user_agent_type, ocean.config.batch_work_size + # create event context per resource kind, so resync method could have access to the resource config + # as we might have multiple resources with the same kind name + async with event_context( + EventType.RESYNC, + trigger_type=trigger_type, + resource_config=resource, + attributes={"resource_kind": resource.kind}, + ): + creation_results.append( + await self._register_in_batches( + resource, user_agent_type, ocean.config.batch_work_size + ) ) - ) flat_created_entities, errors = zip_and_sum(creation_results) or [[], []] if errors: