Skip to content

Automate browser based workflows with AI

Scope the public eval artifact lookup to the eval org (SKY-12639 follow-up) (#7530)

Aaron Perez9f3ad0df2745
diff --git a/skyvern/forge/sdk/db/repositories/artifacts.py b/skyvern/forge/sdk/db/repositories/artifacts.py
index 2c7a8d068..fb1353c7e 100644
--- a/skyvern/forge/sdk/db/repositories/artifacts.py
+++ b/skyvern/forge/sdk/db/repositories/artifacts.py
@@ -284,6 +284,7 @@ class ArtifactsRepository(BaseRepository):
thought_id: str | None = None,
task_v2_id: str | None = None,
limit: int | None = None,
+ include_legacy_null_org: bool = True,
) -> list[Artifact]:
async with self.Session() as session:
# Build base query
@@ -303,11 +304,15 @@ class ArtifactsRepository(BaseRepository):
query = query.filter_by(observer_thought_id=thought_id)
if task_v2_id is not None:
query = query.filter_by(observer_cruise_id=task_v2_id)
- # Handle backward compatibility where old artifact rows were stored with organization_id NULL
if organization_id is not None:
- query = query.filter(
- or_(ArtifactModel.organization_id == organization_id, ArtifactModel.organization_id.is_(None))
- )
+ if include_legacy_null_org:
+ # Backward compatibility: old artifact rows were stored with organization_id NULL.
+ # Only safe when the entity id is already trusted to belong to the caller's org.
+ query = query.filter(
+ or_(ArtifactModel.organization_id == organization_id, ArtifactModel.organization_id.is_(None))
+ )
+ else:
+ query = query.filter(ArtifactModel.organization_id == organization_id)
query = query.order_by(ArtifactModel.created_at.desc())