Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions src/rapidata/rapidata_client/config/upload_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ class UploadConfig(BaseModel):
maxWorkers: int = Field(default=10)
maxRetries: int = Field(default=3)
chunkSize: int = Field(default=50)
cache_uploads: bool = Field(default=True)

Copilot AI Nov 10, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new cache_uploads field is not documented in the class docstring. Add documentation for this field explaining that it controls whether uploaded assets are cached to avoid duplicate uploads.

Copilot uses AI. Check for mistakes.
20 changes: 20 additions & 0 deletions src/rapidata/rapidata_client/datapoints/_asset_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,32 @@
from rapidata.service.openapi_service import OpenAPIService
from rapidata.rapidata_client.config import logger
from rapidata.rapidata_client.config import tracer
from rapidata.rapidata_client.config import rapidata_config


class AssetUploader:
def __init__(self, openapi_service: OpenAPIService):
self.openapi_service = openapi_service
self._upload_cache: dict[str, str] = {}

def _get_cache_key(self, asset: str) -> str:
"""Generate cache key for an asset."""
if re.match(r"^https?://", asset):
return asset
else:
stat = os.stat(asset)

Copilot AI Nov 10, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The _get_cache_key method calls os.stat(asset) without checking if the file exists first. This will raise FileNotFoundError for non-existent files. However, the file existence check happens later in upload_asset at line 44. This causes cache key generation to fail before the proper error handling. Consider adding existence check in _get_cache_key or handling the exception appropriately.

Suggested change
stat = os.stat(asset)
try:
stat = os.stat(asset)
except FileNotFoundError:
raise FileNotFoundError(f"File not found: {asset}")

Copilot uses AI. Check for mistakes.
# Combine path, size, and modification time
return f"{asset}:{stat.st_size}:{stat.st_mtime_ns}"

def upload_asset(self, asset: str) -> str:
with tracer.start_as_current_span("AssetUploader.upload_asset"):
logger.debug("Uploading asset: %s", asset)
assert isinstance(asset, str), "Asset must be a string"

asset_key = self._get_cache_key(asset)
if asset_key in self._upload_cache:
logger.debug("Asset found in cache")
return self._upload_cache[asset_key]

if re.match(r"^https?://", asset):
response = self.openapi_service.asset_api.asset_url_post(
Expand All @@ -30,6 +46,10 @@ def upload_asset(self, asset: str) -> str:
response = self.openapi_service.asset_api.asset_file_post(
file=asset,
)
logger.info(f"Asset uploaded: {response.file_name}")
if rapidata_config.upload.cache_uploads:
self._upload_cache[asset_key] = response.file_name
logger.debug("Asset added to cache")

Copilot AI Nov 10, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The debug log 'Asset added to cache' is always executed regardless of whether caching is enabled or the asset was actually added to cache. Move this log statement inside the if rapidata_config.upload.cache_uploads: block on line 50.

Suggested change
logger.debug("Asset added to cache")
logger.debug("Asset added to cache")

Copilot uses AI. Check for mistakes.
return response.file_name

def get_uploaded_text_input(
Expand Down
Loading