1

hello I am having this problem when i receive a put request in my app:

Here is my router:

@product_router.put("/{id}", response_model=ProductUpdateResponseSchema)
@authenticated(validate=[Validation.IS_ADMIN])
def update_product(id: str, payload: ProductUpdateSchema):
    """Updates a product."""

    product = ProductService.update(id, payload.dict(exclude_none=True))
    return product

and here my schema:

class ProductUpdateSchema(BaseSchema):
    """Product Update Schema."""

    name: Optional[str]  
    description: Optional[List[str]] 
    min_amount_value: Optional[float] = Field(alias="amount_min")
    max_amount_value: Optional[float] = Field(alias="amount_max")
    amount_help: Optional[str]
    information: Optional[str]
    rate_without_iva: Optional[float] = Field(alias="rate")
    iva_rate: Optional[float] = Field(alias="tax_rate")
    rate_help: Optional[str]
    line_group: Optional[str]
    restricted: Optional[str]
    active: Optional[bool]
    grace_period: Optional[int]
    requires_supplier: Optional[bool]
    requires_amount: Optional[bool]

    @root_validator
    def format(cls, values):

        if restricted := values.get('restricted'):
            values['restricted'] = LineCreditLegalPerson[restricted].value
        else:
            values['restricted'] = None

        return values

i have tried receiving the payload as a json type and then parsing it with the schema and also i have tried with jsonable_encoder(payload), but i have still the same issue

  • You might find [this answer](https://stackoverflow.com/a/73974946/17865804) helpful (especially, Option 2) – Chris Mar 05 '23 at 18:08
  • Please search for the error message online, there are literally hundreds of similar questions just here! At the very least, if none of those have a sufficient answer, you will be able to ask a more specific question. As a new user here, please also take the [tour] and read [ask]. – Ulrich Eckhardt Mar 05 '23 at 18:12
  • @Chris I thinnk I am having that problem but with the request payload, I know that fastapi serialize the payload under the hood but probably is not doing it well because when a try to update in the database with that payload i am having this issue. i have tried receiving the payload as a json and parsed it after but still having the issue – Pablo Cimato Mar 05 '23 at 18:37

0 Answers0