Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

157
Vistas
Different behavior Field in pydantic and SQLModel in OpenAPI spec

To my knowledge, SQLmodel is partially based on pydantic. Nevertheless, I get a different resulting OpenAPI specification when using the Field function from SQLmodel in FastAPI.

For example, look at the following example:

from typing import Optional
from fastapi import FastAPI
from sqlmodel import Field, SQLModel

app = FastAPI()

class Model(SQLModel):
    nullable_param: Optional[int] = Field(None, nullable=True)

@app.get("/test", response_model=Model)
def foo():
    return Model(nullable_param=3)

This code runs and a GET on the test endpoint correctly returns {"nullable_param":3}. However, the resulting OpenAPI specification for Model is the following:

{
    "Model":{
        "title":"Model",
        "type":"object",
        "properties":{
            "nullable_param":{"title":"Nullable Param","type":"integer"}
        }
    }
}

Note that nullable_param lacks the nullable=true attribute!

When I import Field directly from pydantic (from pydantic import Field), it does include this attribute:

{
    "Model":{
        "title":"Model",
        "type":"object",
        "properties":{
             "nullable_param":{ "title":"Nullable Param", "type":"integer", "nullable":true }
        }
    }
}

Am I doing something wrong, or is there perhaps a bug in the Field implementation of SQLModel in a FastAPI context?

pydantic 1.8.2 fastapi 0.74.1 sqlmodel 0.0.6 python 3.8.12

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda