Questions tagged [flask-marshmallow]

106 questions
30
votes
6 answers

Update row (SQLAlchemy) with data from marshmallow

I'm using Flask, Flask-SQLAlchemy, Flask-Marshmallow + marshmallow-sqlalchemy, trying to implement REST api PUT method. I haven't found any tutorial using SQLA and Marshmallow implementing update. Here is the code: class NodeSchema(ma.Schema): #…
gcerar
  • 920
  • 1
  • 13
  • 24
8
votes
3 answers

Flask-Marshmallow AttributeError: List Object has no Attribute 'data'

I have a local SQLlite DB which I have connected through the code below: ''' from flask import Flask, jsonify, request from flask_sqlalchemy import SQLAlchemy from sqlalchemy import Column, Integer, String, Float import os from flask_marshmallow…
8
votes
3 answers

How to handle file upload validations using Flask-Marshmallow?

I'm working with Flask-Marshmallow for validating request and response schemas in Flask app. I was able to do simple validations for request.form and request.args when there are simple fields like Int, Str, Float etc. I have a case where I need to…
Underoos
  • 4,708
  • 8
  • 42
  • 85
4
votes
0 answers

Serialization with relationships very slow with Marshmallow

I have the following example table in my DB which I manage mit Flask_SQLAlchemy. class Employee(db.Model): __tablename__ = 'employee' id = db.Column(db.Integer, primary_key=True) salutation = db.Column(db.String(250), nullable=False) …
4
votes
2 answers

sqlalchemy.orm.exc.UnmappedInstanceError: Class 'builtins.dict' is not mapped

I'm trying to insert a new User into a DB using SQLAlchemy and Marshmallow. The user parameter is received from an API endpoint. Everything works until I get to this line in the create function: db.session.add(new_user) The value of the new_user…
4
votes
2 answers

Flask-marshmallow dump of flask-sqlalchemy outer join returns empty

I have two tables, PackMatData and ColorData: class PackMatData(db.Model): id = db.Column(db.Integer, primary_key=True) unique_name = db.Column(db.String(20), index=True, unique=True) se_name = db.Column(db.String(20), index=True) …
3
votes
2 answers

SQLALchemy .query: Unresolved attribute reference 'query' for class 'Car'

I have an issue that was already mentioned here https://youtrack.jetbrains.com/issue/PY-44557 But I couldn't find a solution yet. I'm using Python Flask with SQLAlchemy to create an API service. Here are my imports: from flask import Flask, jsonify,…
3
votes
4 answers

Marshmallow custom validation message for email

I use the following schema to validate data: class UserSchema(db_schema.Schema): email = data_fields.Email(required = True, error_messages={ 'required': 'Email is mandatory field.', 'type': 'The manager email is not…
mimic
  • 4,897
  • 7
  • 54
  • 93
3
votes
0 answers

How to update nested objects in Flask-SQLAlchemy-Marshmallow

Could you help me to update nested objects in Flask-SQLAlchemy-Marshmallow. Here is the model Parent Model class ParentModel(db.Model): __tablename__ = "parent" id = db.Column(db.Integer, primary_key=True) parent_name =…
3
votes
1 answer

How to validate a list of elements of specific type in marshmallow?

I have a POST endpoint in flask which takes a json data which contains a key - collections which has a list as value which in turn contains list of dictionaries containing specific keys in it. I'm trying to validate the request.json but couldn't…
Underoos
  • 4,708
  • 8
  • 42
  • 85
3
votes
1 answer

flask-marshmallow serialize datetime to unix timestamp?

Default, DateTime fields will be serialized to a format like 2020-02-02T13:25:33, but I want to serialized it to unix timestamp. I've read flask-marshmallow documents and marshmallow documents, I only find ways to custom the output datetime format.…
einverne
  • 6,454
  • 6
  • 45
  • 91
2
votes
1 answer

Nesting in Python and Marshmallow with a field that does not exist in the database

I have these schemas in Marshmallow: class Parents(Schema): father = fields.String(data_key="father") mother = fields.String(data_key="mother") class UserSchema(Schema): user_id = fields.Integer(data_key="userID") name =…
2
votes
1 answer

Marshmallow dumps missing 1 required positional argument: 'obj'

For some reason this code produces the error below and i cannot figure out why. In the guide I followed dump was called the same way as far as I can tell and googling has been fruitless especially since this appears to be an error message…
2
votes
0 answers

Prevent marshmallow from querying the db

I want to completely prevent marshmallow from querying the db. Below the explanatory code snippet from flask_sqlalchemy import SQLAlchemy from marshmallow_sqlalchemy import SQLAlchemyAutoSchema from flask_restful import Resource db =…
2
votes
2 answers

Marshmallow returning empty JSON after dumping

I am trying to implement a restful API with Flask using flask-restful, flask-sqlalchemy and flask-marshmallow. I am aware there are many questions about this issue but I still can't figure it out. Solutions like using strict=True in marshmallow…
1
2 3 4 5 6 7