-
Notifications
You must be signed in to change notification settings - Fork 115
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
in #714 we changed how we create GET request model from using attrs to dataclass. This was to support alias with -. The downside was that we need to do validation/conversion in a __post_init__ method.
It seems that this wasn't well tested 😢, and now when we create a Model with extensions the __post_init__ is not ran 😭 😭 😭 😭 😭
from stac_fastapi.api.models import create_get_request_model
from stac_fastapi.extensions.core import FieldsExtension
model = create_get_request_model(extensions=[FieldsExtension()])
model(datetime="yo")
model = create_get_request_model(extensions=[])
model(datetime="yo")
>> HTTPException: 400: Invalid RFC3339 datetime.where
stac-fastapi/stac_fastapi/api/stac_fastapi/api/models.py
Lines 28 to 50 in 494e485
| def create_request_model( | |
| model_name="SearchGetRequest", | |
| base_model: Union[Type[BaseModel], APIRequest] = BaseSearchGetRequest, | |
| extensions: Optional[List[ApiExtension]] = None, | |
| mixins: Optional[Union[List[BaseModel], List[APIRequest]]] = None, | |
| request_type: Optional[str] = "GET", | |
| ) -> Union[Type[BaseModel], APIRequest]: | |
| """Create a pydantic model for validating request bodies.""" | |
| fields = {} | |
| extension_models = [] | |
| # Check extensions for additional parameters to search | |
| for extension in extensions or []: | |
| if extension_model := extension.get_request_model(request_type): | |
| extension_models.append(extension_model) | |
| mixins = mixins or [] | |
| models = extension_models + mixins + [base_model] | |
| # Handle GET requests | |
| if all([issubclass(m, APIRequest) for m in models]): | |
| return make_dataclass(model_name, [], bases=tuple(models)) |
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working