I'm writing classes for satellite components and need to specify dimensions. I've previously had the dimensions specified within the same class:
from sqlmodel import Field
from sqlmodel import SQLModel
class PropulsionSystemInput(SQLModel):
"""Propulsion system input class
This class is used to validate the input data for the add_propulsion_system route.
"""
name: str
manufacturer: str
date_of_development: str
weight: float
dimensions_x: float = Field(ge=0)
dimensions_y: float = Field(ge=0)
dimensions_z: float = Field(ge=0)
power: float
thrust: float
fuel_type: str
fuel_capacity: float
fuel_consumption: float
Although this works, it isn't really functional and I defined a class:
from sqlmodel import SQLModel
class Dimensions(SQLModel):
"""Dimensions class
This class is used to define the database table for dimensions.
It adds an id field to the DimensionsInput class."""
x: float
y: float
z: float
and updated the PropulsionSystemInput
class to:
from sqlmodel import SQLModel
from backend.schemas.components.dimensions_schema import Dimensions
class PropulsionSystemInput(SQLModel):
"""Propulsion system input class
This class is used to validate the input data for the add_propulsion_system route.
"""
name: str
manufacturer: str
date_of_development: str
weight: float
dimensions: Dimensions
power: float
thrust: float
fuel_type: str
fuel_capacity: float
fuel_consumption: float
However, when testing i get the following error:
ValueError: The field dimensions has no matching SQLAlchemy type
I'm new to python and fastapi, so I googled, chatgpt'ed, copiloted and just couldn't get this to work.
I thought this question was pretty close to what I wanted to achieve, but somehow adapting it to my project didn't work.
Any help appreciated