mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-04-24 02:32:01 +08:00
fix parse_json_fields
This commit is contained in:
@@ -69,11 +69,13 @@ class Subscribe(BaseModel):
|
||||
@validator('sites', pre=True)
|
||||
def parse_json_fields(cls, value):
|
||||
if value:
|
||||
try:
|
||||
return json.loads(value)
|
||||
except json.JSONDecodeError:
|
||||
raise ValueError(f"Invalid JSON string: {value}")
|
||||
return {}
|
||||
if isinstance(value, str):
|
||||
try:
|
||||
return json.loads(value)
|
||||
except json.JSONDecodeError:
|
||||
return []
|
||||
return value
|
||||
return []
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
@@ -26,10 +26,12 @@ class UserBase(BaseModel):
|
||||
@validator('permissions', 'settings', pre=True)
|
||||
def parse_json_fields(cls, value):
|
||||
if value:
|
||||
try:
|
||||
return json.loads(value)
|
||||
except json.JSONDecodeError:
|
||||
raise ValueError(f"Invalid JSON string: {value}")
|
||||
if isinstance(value, str):
|
||||
try:
|
||||
return json.loads(value)
|
||||
except json.JSONDecodeError:
|
||||
return {}
|
||||
return value
|
||||
return {}
|
||||
|
||||
class Config:
|
||||
|
||||
Reference in New Issue
Block a user