-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Description
Description
When deploying the project to Render, the POST /store/<store_id>/tag endpoint crashes.
The same request works locally with insomnia client, but fails on Render due to some Marshmallow behavior.
Steps to Reproduce
- Deploy the project to Render.
- Send a POST request to
/store/1/tagwith body:
{
"name": "Food"
}The server responds with an error:
'dict' object has no attribute '_sa_instance_state'
Solution
@blp.response(200, TagSchema) # Response can include items and store
def post(self, tag_data, store_id):
if TagModel.query.filter(
TagModel.store_id == store_id,
TagModel.name == tag_data["name"]
).first():
abort(400, message="A tag with that name already exists in that store.")
tag = TagModel(**tag_data, store_id=store_id)
try:
db.session.add(tag)
db.session.commit()
except SQLAlchemyError as e:
abort(500, message=str(e))
return tag
The correct fix is to separate schemas (PlainTagSchema for input, TagSchema for output).
I hope this bug solution will help you.
Metadata
Metadata
Assignees
Labels
No labels