uipath-python icon indicating copy to clipboard operation
uipath-python copied to clipboard

BucketsService is not properly cached - creates new instance on each property access

Open uipreliga opened this issue 1 year ago • 1 comments

Description

The BucketsService property in the UiPath class has a caching bug where it creates a new instance on every property access instead of returning the cached instance. This is inconsistent with other services like AttachmentsService and ConnectionsService which properly return cached instances.

Current Behavior

Every time sdk.buckets is accessed, a new BucketsService instance is created, even though the property checks for a cached instance in self._buckets_service.

Expected Behavior

The buckets property should return the cached instance stored in self._buckets_service after the first access, similar to how other services work.

Root Cause

The bug is in /src/uipath/_uipath.py at line 98:

@property
def buckets(self) -> BucketsService:
    if not self._buckets_service:
        self._buckets_service = BucketsService(
            self._config, self._execution_context
        )
    return BucketsService(self._config, self._execution_context)  # BUG: Always returns new instance

The method stores the instance in self._buckets_service but then returns a new instance instead of the cached one.

Impact

  • Performance: Creates unnecessary object instances on each access
  • Memory: Potential memory waste from multiple instances
  • Consistency: Breaks the singleton pattern expected for service instances
  • Integration Issues: May cause problems in downstream packages that expect service instances to be cached

Steps to Reproduce

  1. Create a simple test script:
from uipath import UiPath

sdk = UiPath()
buckets1 = sdk.buckets
buckets2 = sdk.buckets

print(f"Same instance? {buckets1 is buckets2}")  # Prints: False (should be True)
  1. Run the script and observe that buckets1 and buckets2 are different instances

Proposed Fix

Change line 98 to return the cached instance:

@property
def buckets(self) -> BucketsService:
    if not self._buckets_service:
        self._buckets_service = BucketsService(
            self._config, self._execution_context
        )
    return self._buckets_service  # Return the cached instance

Related Issues

  • Similar issue was fixed for ConnectionsService in recent changes
  • Other services like AttachmentsService, FolderService, and ConnectionsService implement caching correctly

Priority

Medium - While not critical, this inconsistency could lead to unexpected behavior and performance issues in production environments.

uipreliga avatar Oct 08 '25 16:10 uipreliga

closing the issue as it was already hadled

radu-mocanu avatar Apr 21 '26 10:04 radu-mocanu