Skip to content

HashModel doesn't work on pydantic  #3

Description

@amevide998

code :

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from redis_om import get_redis_connection, HashModel

app = FastAPI()

app.add_middleware(
CORSMiddleware,
allow_origins=['http://localhost:3000'],
allow_methods=[''],
allow_headers=['
']
)

redis = get_redis_connection(
host="redis-11844.c135.eu-central-1-1.ec2.cloud.redislabs.com",
port=11844,
password="pRdcpRkKPFn6UnEFskrDGxrmFbf5T9ER",
decode_responses=True
)

class Product(HashModel):
name: str
price: float
quantity: int

class Meta:
    database = redis

@app.post('/products')
def create(product: Product):
return product.save()

error message :

fastapi.exceptions.FastAPIError: Invalid args for response field! Hint: check that <class 'main.Product'> is a valid Pydantic field type. If you are using a return type annotation that is not a valid Pydantic field (e.g. Union[Response, dict, None]) you can disable generating the response model from the type annotation with the path operation decorator parameter response_model=None. Read more: https://fastapi.tiangolo.com/tutorial/response-model/

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions