scalablescripts / fastapi-microservices

117 stars 70 forks source link

Your code is not working plz help me to figureout my mistake #2

Closed PARKER-X closed 1 year ago

PARKER-X commented 1 year ago

My code https://github.com/scalablescripts/fastapi-microservices/tree/master/inventory Post requst gives error

vcnwafor commented 1 year ago

@PARKER-X post a sample of the error.

PARKER-X commented 1 year ago

@PARKER-X post a sample of the error.

I think these error produced by redis fastapi.exceptions.FastAPIError: Invalid args for response field! Hint: check that <class 'inventory.schema.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/

vcnwafor commented 1 year ago

below is the changes I made to get it working. `from pydantic import BaseModel

class ProductCreate(BaseModel): name: str price: float quantity: int

@app.post('/products') def create(product: ProductCreate): print("product found", product) new_product = Product(**product.dict()) new_product.save() return new_product `

PARKER-X commented 1 year ago

@vcnwafor It's not working yet

PARKER-X commented 1 year ago

@vcnwafor Finally error resolved i need to install pydantic version 1 redis_om didn;t support pydantic v2ans now error is resolved Thanks!