You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am getting RecursionError: maximum recursion depth exceeded while calling a Python object error for following code, Is there any other way to selecting the schema based on a value
importmarshmallowfrommarshmallowimportfields, post_loadclassFoodSchema(marshmallow.Schema):
food_type=fields.String()
@post_loaddefmake_food(self, data, **kwargs):
food_type=data.get('food_type', '').lower()
iffood_type=='fruit':
returnFruitSchema().load(data)
eliffood_type=='vegetable':
returnVegetableSchema().load(data)
eliffood_type=='meat':
returnMeatSchema().load(data)
else:
raiseValueError("Invalid food type")
classFruitSchema(FoodSchema):
# Add fields specific to the Fruit class hereclassVegetableSchema(FoodSchema):
# Add fields specific to the Vegetable class hereclassMeatSchema(FoodSchema):
# Add fields specific to the Meat class hereprint(FoodSchema().load({'food_type':'fruit'}))
The text was updated successfully, but these errors were encountered:
I am getting
RecursionError: maximum recursion depth exceeded while calling a Python object
error for following code, Is there any other way to selecting the schema based on a valueThe text was updated successfully, but these errors were encountered: