|
22 | 22 | from ..common._config import UiPathApiConfig |
23 | 23 | from ..common._execution_context import UiPathExecutionContext |
24 | 24 | from ..common._models import Endpoint, RequestSpec |
| 25 | +from ..constants import HEADER_SOURCE |
25 | 26 | from ..errors._enriched_exception import EnrichedException |
26 | 27 | from ..orchestrator._folder_service import FolderService |
27 | 28 | from ._entity_resolution import RoutingStrategy, create_routing_strategy |
@@ -518,16 +519,18 @@ async def retrieve_records_async( |
518 | 519 | def query_entity_records( |
519 | 520 | self, |
520 | 521 | sql_query: str, |
| 522 | + source: Optional[str] = None, |
521 | 523 | ) -> List[Dict[str, Any]]: |
522 | 524 | """Internal implementation; see :meth:`EntitiesService.query_entity_records`.""" |
523 | | - return self._query_entities_for_records(sql_query) |
| 525 | + return self._query_entities_for_records(sql_query, source) |
524 | 526 |
|
525 | 527 | async def query_entity_records_async( |
526 | 528 | self, |
527 | 529 | sql_query: str, |
| 530 | + source: Optional[str] = None, |
528 | 531 | ) -> List[Dict[str, Any]]: |
529 | 532 | """Async variant of :meth:`query_entity_records`.""" |
530 | | - return await self._query_entities_for_records_async(sql_query) |
| 533 | + return await self._query_entities_for_records_async(sql_query, source) |
531 | 534 |
|
532 | 535 | # ------------------------------------------------------------------ |
533 | 536 | # Attachments |
@@ -680,22 +683,28 @@ def validate_entity_batch( |
680 | 683 | # Internal helpers — request specs |
681 | 684 | # ------------------------------------------------------------------ |
682 | 685 |
|
683 | | - def _query_entities_for_records(self, sql_query: str) -> List[Dict[str, Any]]: |
| 686 | + def _query_entities_for_records( |
| 687 | + self, sql_query: str, source: Optional[str] = None |
| 688 | + ) -> List[Dict[str, Any]]: |
684 | 689 | """Synchronously run a validated SQL query through the federated query engine.""" |
685 | 690 | self._validate_sql_query(sql_query) |
686 | 691 | routing_context = self._routing_strategy.resolve() |
687 | | - spec = self._query_entity_records_spec(sql_query, routing_context) |
688 | | - response = self.request(spec.method, spec.endpoint, json=spec.json) |
| 692 | + spec = self._query_entity_records_spec(sql_query, routing_context, source) |
| 693 | + response = self.request( |
| 694 | + spec.method, spec.endpoint, json=spec.json, headers=spec.headers |
| 695 | + ) |
689 | 696 | return response.json().get("results", []) |
690 | 697 |
|
691 | 698 | async def _query_entities_for_records_async( |
692 | | - self, sql_query: str |
| 699 | + self, sql_query: str, source: Optional[str] = None |
693 | 700 | ) -> List[Dict[str, Any]]: |
694 | 701 | """Asynchronously run a validated SQL query through the federated query engine.""" |
695 | 702 | self._validate_sql_query(sql_query) |
696 | 703 | routing_context = await self._routing_strategy.resolve_async() |
697 | | - spec = self._query_entity_records_spec(sql_query, routing_context) |
698 | | - response = await self.request_async(spec.method, spec.endpoint, json=spec.json) |
| 704 | + spec = self._query_entity_records_spec(sql_query, routing_context, source) |
| 705 | + response = await self.request_async( |
| 706 | + spec.method, spec.endpoint, json=spec.json, headers=spec.headers |
| 707 | + ) |
699 | 708 | return response.json().get("results", []) |
700 | 709 |
|
701 | 710 | @staticmethod |
@@ -956,17 +965,20 @@ def _retrieve_records_spec( |
956 | 965 | def _query_entity_records_spec( |
957 | 966 | sql_query: str, |
958 | 967 | routing_context: Optional[QueryRoutingOverrideContext] = None, |
| 968 | + source: Optional[str] = None, |
959 | 969 | ) -> RequestSpec: |
960 | 970 | """Build the POST spec for the federated SQL query endpoint.""" |
961 | 971 | body: Dict[str, Any] = {"query": sql_query} |
962 | 972 | if routing_context: |
963 | 973 | body["routingContext"] = routing_context.model_dump( |
964 | 974 | by_alias=True, exclude_none=True |
965 | 975 | ) |
| 976 | + headers = {HEADER_SOURCE: source} if source else {} |
966 | 977 | return RequestSpec( |
967 | 978 | method="POST", |
968 | 979 | endpoint=Endpoint("datafabric_/api/v1/query/execute"), |
969 | 980 | json=body, |
| 981 | + headers=headers, |
970 | 982 | ) |
971 | 983 |
|
972 | 984 | @staticmethod |
|
0 commit comments