Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump fastapi and add pydantic compatibility #1529

1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Please follow the established format:

## Bug fixes and other changes

- Add support for fastapi >= 0.100.0 (#1529)
- Fix dataset factory patterns in Experiment Tracking. (#1588)

# Release 6.6.1
Expand Down
2 changes: 1 addition & 1 deletion package/features/steps/lower_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ipython==7.0.0
fastapi==0.73.0
fastapi==0.100.0
fsspec==2021.4
aiofiles==22.1.0
uvicorn[standard]==0.22.0
Expand Down
49 changes: 29 additions & 20 deletions package/kedro_viz/api/rest/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
# pylint: disable=missing-class-docstring,too-few-public-methods,invalid-name
import abc
import logging
from typing import Any, Dict, List, Optional, Union
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union

import fsspec
import orjson
import packaging
from fastapi.encoders import jsonable_encoder
from fastapi.responses import JSONResponse, ORJSONResponse
from kedro.io.core import get_protocol_and_path
from pydantic import BaseModel

fdroessler marked this conversation as resolved.
Show resolved Hide resolved
from kedro_viz.api.rest.utils import get_package_version
from kedro_viz.data_access import data_access_manager
Expand All @@ -24,6 +23,16 @@
TranscodedDataNodeMetadata,
)

if TYPE_CHECKING:
from pydantic import BaseModel
else:
try:
# Triggered if pydantic v2 is installed
from pydantic.v1 import BaseModel
except ImportError:
# Triggered if pydantic v1 is installed
from pydantic import BaseModel

logger = logging.getLogger(__name__)

_FSSPEC_PACKAGE_NAME = "fsspec"
Expand All @@ -47,7 +56,7 @@ class BaseGraphNodeAPIResponse(BaseAPIResponse):
type: str

# If a node is a ModularPipeline node, this value will be None, hence Optional.
modular_pipelines: Optional[List[str]]
modular_pipelines: Optional[List[str]] = None


class TaskNodeAPIResponse(BaseGraphNodeAPIResponse):
Expand Down Expand Up @@ -81,9 +90,9 @@ class Config:


class DataNodeAPIResponse(BaseGraphNodeAPIResponse):
layer: Optional[str]
dataset_type: Optional[str]
stats: Optional[Dict]
layer: Optional[str] = None
dataset_type: Optional[str] = None
stats: Optional[Dict] = None

class Config:
schema_extra = {
Expand All @@ -108,12 +117,12 @@ class Config:


class TaskNodeMetadataAPIResponse(BaseAPIResponse):
code: Optional[str]
filepath: Optional[str]
parameters: Optional[Dict]
code: Optional[str] = None
filepath: Optional[str] = None
parameters: Optional[Dict] = None
inputs: List[str]
outputs: List[str]
run_command: Optional[str]
run_command: Optional[str] = None

class Config:
schema_extra = {
Expand All @@ -129,14 +138,14 @@ class Config:


class DataNodeMetadataAPIResponse(BaseAPIResponse):
filepath: Optional[str]
filepath: Optional[str] = None
type: str
plot: Optional[Dict]
image: Optional[str]
tracking_data: Optional[Dict]
run_command: Optional[str]
preview: Optional[Dict]
stats: Optional[Dict]
plot: Optional[Dict] = None
image: Optional[str] = None
tracking_data: Optional[Dict] = None
run_command: Optional[str] = None
preview: Optional[Dict] = None
stats: Optional[Dict] = None

class Config:
schema_extra = {
Expand All @@ -152,8 +161,8 @@ class TranscodedDataNodeMetadataAPIReponse(BaseAPIResponse):
filepath: str
original_type: str
transcoded_types: List[str]
run_command: Optional[str]
stats: Optional[Dict]
run_command: Optional[str] = None
stats: Optional[Dict] = None


class ParametersNodeMetadataAPIResponse(BaseAPIResponse):
Expand Down Expand Up @@ -199,7 +208,7 @@ class NamedEntityAPIResponse(BaseAPIResponse):
"""

id: str
name: Optional[str]
name: Optional[str] = None


class ModularPipelineChildAPIResponse(BaseAPIResponse):
Expand Down
6 changes: 3 additions & 3 deletions package/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
packaging~=23.0
kedro>=0.17.5
ipython>=7.0.0, <9.0
fastapi>=0.73.0, <0.96.0
fsspec[s3]>=2021.4, <2024.1
aiofiles>=22.1.0
fastapi>=0.100.0,<0.102.0
fsspec[s3]>=2021.4, <2024.1
aiofiles==22.1.0
uvicorn[standard]~=0.22.0
watchgod~=0.8.2
plotly>=4.0
Expand Down
2 changes: 1 addition & 1 deletion package/test_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ behave~=1.2
black~=23.3
boto3~=1.26
flake8~=5.0
fastapi[all]>=0.73.0, <0.96.0
fastapi[all]>=0.73.0, <0.104.0
isort~=5.11
matplotlib~=3.5
mypy~=1.0
Expand Down