Handle double-JSON-encoded VarData
In some paths, a Var will have JSON encoded data that is itself JSON encoded again (like Var[dict] types). If we can't decode the VarData up front, try to double decode it as a fallback.
This commit is contained in:
parent
cdc2f4f6e0
commit
6ae08c38db
@ -250,9 +250,9 @@ def _decode_var(value: str) -> tuple[VarData | None, str]:
|
|||||||
try:
|
try:
|
||||||
# TODO: go one pydantic api level lower to load json directly into dict
|
# TODO: go one pydantic api level lower to load json directly into dict
|
||||||
return VarData.model_validate_json(s).model_dump()
|
return VarData.model_validate_json(s).model_dump()
|
||||||
except pydantic_core.ValidationError as e:
|
except pydantic_core.ValidationError:
|
||||||
raise ValueError(f"Invalid VarData: {s}") from e
|
# The value may have been JSON-encoded twice, so try again.
|
||||||
# return VarData.model_validate(var_data_config.json_loads(f'"{s}"'))
|
return json.loads(json.loads(f'"{s}"'))
|
||||||
|
|
||||||
# Compile regex for finding reflex var tags.
|
# Compile regex for finding reflex var tags.
|
||||||
pattern_re = rf"{constants.REFLEX_VAR_OPENING_TAG}(.*?){constants.REFLEX_VAR_CLOSING_TAG}"
|
pattern_re = rf"{constants.REFLEX_VAR_OPENING_TAG}(.*?){constants.REFLEX_VAR_CLOSING_TAG}"
|
||||||
|
Loading…
Reference in New Issue
Block a user