Skip to content
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
2 changes: 1 addition & 1 deletion packages/uipath-platform/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "uipath-platform"
version = "0.0.19"
version = "0.0.20"
description = "HTTP client library for programmatic access to UiPath Platform"
readme = { file = "README.md", content-type = "text/markdown" }
requires-python = ">=3.11"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import inspect
import sys
import types
from logging import getLogger
from typing import Any, Literal, Union

Expand Down Expand Up @@ -32,6 +33,33 @@
platform_wait_strategy,
)

_THIS_FILE = __file__
_MAX_CALLER_FRAMES = 5


def _get_caller_component() -> str:
try:
current: types.FrameType | None = sys._getframe(1)
for _ in range(_MAX_CALLER_FRAMES):
if current is None:
break
code = current.f_code
if code.co_filename == _THIS_FILE:
current = current.f_back
continue
# Skip frames from third-party libraries (e.g. tenacity)
if "site-packages" in code.co_filename:
current = current.f_back
continue
qualname = code.co_qualname
if "." in qualname:
parts = qualname.rsplit(".", 2)
return f"{parts[-2]}.{parts[-1]}"
current = current.f_back
except Exception:
pass
return ""


class BaseService:
def __init__(
Expand Down Expand Up @@ -78,26 +106,7 @@ def request(
self._logger.debug(f"Request: {method} {url}")
self._logger.debug(f"HEADERS: {kwargs.get('headers', self._client.headers)}")

try:
stack = inspect.stack()

# use the third frame because of the retry decorator
caller_frame = stack[3].frame
function_name = caller_frame.f_code.co_name

if "self" in caller_frame.f_locals:
module_name = type(caller_frame.f_locals["self"]).__name__
elif "cls" in caller_frame.f_locals:
module_name = caller_frame.f_locals["cls"].__name__
else:
module_name = ""
except Exception:
function_name = ""
module_name = ""

specific_component = (
f"{module_name}.{function_name}" if module_name and function_name else ""
)
specific_component = _get_caller_component()

kwargs.setdefault("headers", {})
kwargs["headers"][HEADER_USER_AGENT] = user_agent_value(specific_component)
Expand Down Expand Up @@ -181,24 +190,4 @@ def custom_headers(self) -> dict[str, str]:

@property
def _specific_component(self) -> str:
try:
stack = inspect.stack()

caller_frame = stack[4].frame
function_name = caller_frame.f_code.co_name

if "self" in caller_frame.f_locals:
module_name = type(caller_frame.f_locals["self"]).__name__
elif "cls" in caller_frame.f_locals:
module_name = caller_frame.f_locals["cls"].__name__
else:
module_name = ""
except Exception:
function_name = ""
module_name = ""

specific_component = (
f"{module_name}.{function_name}" if module_name and function_name else ""
)

return specific_component
return _get_caller_component()
2 changes: 1 addition & 1 deletion packages/uipath-platform/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/uipath/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading