summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormontezdesousa <79287829+montezdesousa@users.noreply.github.com>2024-04-02 18:41:48 +0100
committerGitHub <noreply@github.com>2024-04-02 17:41:48 +0000
commit83d03bc2544a412d123ec9137e98dbb5d9d2dc7f (patch)
tree3e5cfc0814229541b760d7105eb40f728f089d8a
parentbc77e071b7dcd73e18b3387ebba36bdebe6430fc (diff)
fix: serialize response before fastapi (#6279)
-rw-r--r--openbb_platform/core/openbb_core/api/router/commands.py13
-rw-r--r--openbb_platform/core/openbb_core/provider/registry_map.py3
2 files changed, 7 insertions, 9 deletions
diff --git a/openbb_platform/core/openbb_core/api/router/commands.py b/openbb_platform/core/openbb_core/api/router/commands.py
index d524156ddbd..2d2ea3e6a11 100644
--- a/openbb_platform/core/openbb_core/api/router/commands.py
+++ b/openbb_platform/core/openbb_core/api/router/commands.py
@@ -117,7 +117,7 @@ def build_new_signature(path: str, func: Callable) -> Signature:
)
-def validate_output(c_out: OBBject) -> OBBject:
+def validate_output(c_out: OBBject) -> Dict:
"""
Validate OBBject object.
@@ -132,8 +132,8 @@ def validate_output(c_out: OBBject) -> OBBject:
Returns
-------
- OBBject
- Validated OBBject object.
+ Dict
+ Serialized OBBject.
"""
def is_model(type_):
@@ -170,7 +170,7 @@ def validate_output(c_out: OBBject) -> OBBject:
for k, v in c_out.model_copy():
exclude_fields_from_api(k, v)
- return c_out
+ return c_out.model_dump()
def build_api_wrapper(
@@ -188,7 +188,7 @@ def build_api_wrapper(
func.__annotations__ = new_annotations_map
@wraps(wrapped=func)
- async def wrapper(*args: Tuple[Any], **kwargs: Dict[str, Any]):
+ async def wrapper(*args: Tuple[Any], **kwargs: Dict[str, Any]) -> Dict:
user_settings: UserSettings = UserSettings.model_validate(
kwargs.pop(
"__authenticated_user_settings",
@@ -198,8 +198,7 @@ def build_api_wrapper(
execute = partial(command_runner.run, path, user_settings)
output: OBBject = await execute(*args, **kwargs)
- output = validate_output(output)
- return output
+ return validate_output(output)
return wrapper
diff --git a/openbb_platform/core/openbb_core/provider/registry_map.py b/openbb_platform/core/openbb_core/provider/registry_map.py
index eb4573a0efb..b3463b5da79 100644
--- a/openbb_platform/core/openbb_core/provider/registry_map.py
+++ b/openbb_platform/core/openbb_core/provider/registry_map.py
@@ -110,7 +110,7 @@ class RegistryMap:
fetcher: Fetcher,
model_map: dict,
):
- """Merge json schema extra for different providers"""
+ """Merge json schema extra for different providers."""
model: BaseModel = RegistryMap._get_model(fetcher, "query_params")
std_fields = model_map["openbb"]["QueryParams"]["fields"]
extra_fields = model_map[provider]["QueryParams"]["fields"]
@@ -157,7 +157,6 @@ class RegistryMap:
Field(
default=provider_str,
description="The data provider for the data.",
- exclude=True,
),
)