-
-
Notifications
You must be signed in to change notification settings - Fork 630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Send a post request containing nested data, .List(fields.Nested(Schema)), Flask restapi - marshmallow schema #2302
Comments
This appears to be a duplicate of marshmallow-code/flask-smorest#253. The form location implies that the data is a url encoded, not JSON.
https://flask-smorest.readthedocs.io/en/latest/arguments.html#content-type |
in send post request form data: My problem is only in sending nested data and not in uploading files. I get this result in postman: |
in send post request form data: My problem is only in sending nested data and not in uploading files. I get this result in postman: |
Have you tried the custom parser work around in that first issue? |
I have a problem when requesting post with list (nested (schema) so that the input type is not accepted
{
"code": 422,
"errors": {
"form": {
"addresses": {
"0": {
"_schema": [
"Invalid input type."
]
}
}
}
},
"status": "Unprocessable Entity"
}
I am sending the data as form data because I am sending files in the request, I do not want to send the request as json
The request I sent is:
addresses:[{"city":"aa","street_name":"a5"}]
and
addresses:{"city":"aa","street_name":"a5"}
It works without schema but I want to use schema to check the validity of the data
@blp.arguments(Schema, location="form")
I did not find a solution to this problem, can anyone help me
class Address(db.Model):
id = db.Column(db.Integer, primary_key=True)
city = db.Column(db.String(100), nullable=False)
street_name = db.Column(db.String(150), nullable=False)
store_id = db.Column(db.Integer, db.ForeignKey('store.id'), nullable=False)
store= db.relationship('Store', backref='addresses ')
class Store(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(100), nullable=False)
logo = db.Column(db.String(200), nullable=True)
addresses = db.relationship('Address', backref='store', lazy=True)
class AddressSchema(Schema):
id = fields.Int(dump_only=True)
city = fields.Str(required=True)
street_name = fields.Str(required=True)
store_id = fields.Int(required=True)
class StoreSchema(Schema):
id = fields.Int(dump_only=True)
name = fields.Str(required=True)
logo = fields.Str()
addresses = fields.List(fields.Nested(AddressSchema))
The text was updated successfully, but these errors were encountered: