BucketsService is not properly cached - creates new instance on each property access
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
- 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)
- Run the script and observe that
buckets1andbuckets2are 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
ConnectionsServicein recent changes - Other services like
AttachmentsService,FolderService, andConnectionsServiceimplement caching correctly
Priority
Medium - While not critical, this inconsistency could lead to unexpected behavior and performance issues in production environments.
closing the issue as it was already hadled