Object update validator fixed.
This commit is contained in:
@@ -8,7 +8,7 @@ import logging
|
||||
from traceback import format_exc
|
||||
import base64
|
||||
import traceback
|
||||
from pydantic import BaseModel, validator
|
||||
from pydantic import BaseModel, model_validator
|
||||
|
||||
from packetserver.http.dependencies import get_current_http_user
|
||||
from packetserver.http.auth import HttpUser
|
||||
@@ -258,15 +258,15 @@ async def create_binary_object(
|
||||
class ObjectUpdate(BaseModel):
|
||||
name: Optional[str] = None
|
||||
private: Optional[bool] = None
|
||||
data_text: Optional[str] = None # New: update to text content (forces binary=False)
|
||||
data_base64: Optional[str] = None # New: update to binary content (forces binary=True)
|
||||
data_text: Optional[str] = None # Update to text content → forces binary=False
|
||||
data_base64: Optional[str] = None # Update to binary content → forces binary=True
|
||||
|
||||
@validator('data_text', 'data_base64', pre=True, always=True)
|
||||
def check_mutually_exclusive(cls, v, values, field):
|
||||
other_field = 'data_base64' if field.name == 'data_text' else 'data_text'
|
||||
if v is not None and values.get(other_field) is not None:
|
||||
@model_validator(mode='before')
|
||||
@classmethod
|
||||
def check_mutually_exclusive_content(cls, values: dict) -> dict:
|
||||
if values.get('data_text') is not None and values.get('data_base64') is not None:
|
||||
raise ValueError('data_text and data_base64 cannot be provided together')
|
||||
return v
|
||||
return values
|
||||
|
||||
@router.patch("/objects/{uuid}", response_model=ObjectSummary)
|
||||
async def update_object(
|
||||
|
||||
Reference in New Issue
Block a user