[Backend] Fix - Task V2 conversion changes to make new proxy city/state feature work (#4153)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import json
|
||||
from datetime import datetime
|
||||
from enum import StrEnum
|
||||
from typing import Any
|
||||
@@ -5,7 +6,7 @@ from typing import Any
|
||||
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
||||
|
||||
from skyvern.config import settings
|
||||
from skyvern.schemas.runs import ProxyLocationInput
|
||||
from skyvern.schemas.runs import GeoTarget, ProxyLocation, ProxyLocationInput
|
||||
from skyvern.utils.url_validators import validate_url
|
||||
|
||||
DEFAULT_WORKFLOW_TITLE = "New Workflow"
|
||||
@@ -57,6 +58,32 @@ class TaskV2(BaseModel):
|
||||
created_at: datetime
|
||||
modified_at: datetime
|
||||
|
||||
@staticmethod
|
||||
def _parse_proxy_location(proxy_location: ProxyLocationInput | str) -> ProxyLocationInput:
|
||||
"""Handle JSON strings that were persisted to the DB."""
|
||||
if proxy_location is None or isinstance(proxy_location, (ProxyLocation, GeoTarget, dict)):
|
||||
return proxy_location
|
||||
|
||||
if isinstance(proxy_location, str):
|
||||
stripped = proxy_location.strip()
|
||||
if not stripped:
|
||||
return None
|
||||
|
||||
if stripped.startswith("{"):
|
||||
try:
|
||||
parsed = json.loads(stripped)
|
||||
if isinstance(parsed, dict):
|
||||
return GeoTarget.model_validate(parsed)
|
||||
except (json.JSONDecodeError, ValueError):
|
||||
pass
|
||||
|
||||
try:
|
||||
return ProxyLocation(stripped)
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
return proxy_location
|
||||
|
||||
@property
|
||||
def llm_key(self) -> str | None:
|
||||
"""
|
||||
@@ -83,6 +110,11 @@ class TaskV2(BaseModel):
|
||||
|
||||
return validate_url(url)
|
||||
|
||||
@field_validator("proxy_location", mode="before")
|
||||
@classmethod
|
||||
def deserialize_proxy_location(cls, proxy_location: ProxyLocationInput | str) -> ProxyLocationInput:
|
||||
return cls._parse_proxy_location(proxy_location)
|
||||
|
||||
|
||||
class ThoughtType(StrEnum):
|
||||
plan = "plan"
|
||||
@@ -166,3 +198,8 @@ class TaskV2Request(BaseModel):
|
||||
return url
|
||||
|
||||
return validate_url(url)
|
||||
|
||||
@field_validator("proxy_location", mode="before")
|
||||
@classmethod
|
||||
def deserialize_proxy_location(cls, proxy_location: ProxyLocationInput | str) -> ProxyLocationInput:
|
||||
return TaskV2._parse_proxy_location(proxy_location)
|
||||
|
||||
Reference in New Issue
Block a user