Questions tagged [marshmallow]

Marshmallow is an ORM/ODM/framework-agnostic library for converting complex datatypes, such as objects, to and from native Python datatypes. (For Questions about Android Marshmallow use the tag [android-6.0-marshmallow].)

-1
votes
1answer
33 views

TypeError: 'Product' object is not subscriptable in Flask

I am new to python and flask, I am learning to build Flask-rest-api. I am using SQLAlchemy as the db. I tried to post data using postman to the api and I get the TypeError: Object is not subscriptable....
1
vote
1answer
27 views

Marshmallow field of any type

I want to specify a marshmallow schema. For one of my fields, I don't want the schema to validate the type, but to simply pass it on. This is because the type could be anything, we don't know ahead of ...
-1
votes
0answers
33 views

What's a good checklist for error checking a Flask API? [closed]

I'm designing a REST API using Flask, SQLAlchemy and Marshmallow. I'm trying to come up with a list of things to check in code - code below has no such checks yet. What error checks are recommended ...
2
votes
0answers
47 views

Using python library flask-rest-jsonapi without id as primary key

I am using Python library flask-rest-jsonapi to design an API. The library uses flask-sqlalchemy and marshmallow. Marshmallow has a requirement to have an "id" and a "type" field mandatory in the ...
0
votes
1answer
21 views

Override field schema based on data - Marshmallow

I'm just getting started with marshmallow so if there's a more elegant way to solve the issue please let me know. Fields will be varied based on the user type (student/staff) { "type": "student", ...
0
votes
2answers
34 views

How to load query string arguments in Flask Marshmallow schema

I have a POST request defined in my Flask app as below: https://www.foo.com/<foo_id>?bar_id=3 I am getting the path parameter foo_id as below: from flask_restplus import Namespace, Resource ...
0
votes
1answer
18 views

ma.Nested probably does not work sqlalchemy and marshmallow

I have one to many relationships between tables in a database and I want to get the data using an API. I think that ma.Nested does not work because I don't get all the fields can anyone help me? I ...
0
votes
0answers
14 views

SQLAlchemy outer join does not show nested data while serializing [duplicate]

I have 2 SQLAlchemy models and some marshmellow-sqlalchemy schemas associated with them: from sqlalchemy import Column, Integer, VARCHAR, ForeignKey, Float, TIMESTAMP, DATE, TEXT, BOOLEAN, SMALLINT, ...
0
votes
0answers
17 views

How to load in arguments using marshmallow and flask_restful?

I have a flask_restful API set up but want users to pass numpy arrays when making a post call. I first tried using reqparse from flask_restful but it doesn't support data types of numpy.array. I am ...
0
votes
0answers
22 views

using marshmallow in flask manipulating data before inserting data in database

I am trying to validate my data which i am posting through post request and i want to check if the data i proper or not and with that i want to do type casting and manipulate the data. I have tried ...
0
votes
0answers
10 views

How to unite two marshmellow schemes in one

I use marshmallow to validate my output. I have two marshmallow schemes class IdentitiesList(Schema): items = fields.List(fields.String, required=True) class UsersListSchema(Schema): items = ...
0
votes
2answers
44 views

How to perform update partially in Flask?

Is there anyway to update with PUT method in flask restul with partially fields? currently my PUT method perform this however if the fields it's not there gonna throw error. item = ItemModel....
0
votes
2answers
40 views

Sqlalchemy-Marshmallow - Nested field not displaying any data

I was having no problem using nested fields in my flask app when using marshmallow-sqlalchemy with Flask-SQLAlchemy. Now that I've switched from Flask-SQLAlchemy to just SQLAlchemy (for a few ...
-1
votes
0answers
19 views

Marshmallow error with many to many relationships

i try to deserialize data with marshmallow before save here in db but i get error with my relationships many to many and i don t understand the reason. this is a little part of my code : dream_cat =...
0
votes
0answers
20 views

Python Marshmallow: INCLUDE specific parameter

I have the next schema and data: from marshmallow import Schema, fields, INCLUDE class MarshmallowSchema(Schema): field1 = fields.Str() field2 = fields.Str() json = { "field1":"string1", ...
0
votes
1answer
121 views

Python parse Json with key with special character

Hello I'm using python marshmallow package to convert a json file into python objects. However the one of the keys contains special character. from marshmallow import Schema fakeJson = {"A":"33","$C"...
0
votes
1answer
39 views

Flask Marshmallow JSON fields

I have defined a POST call would that needs data: { "one" : "hello", "two" : "world", "three" : { "abc": "123", "def": false } } For this,...
0
votes
0answers
15 views

Marshmallow serialization issue with @pre_dump helper

I have the below schema in Marshmallow class JobSchema(ma.ModelSchema): title = fields.Str(required=True, validate=[validate.Length(min=4, max=80)]) city = fields.Str(required=True, ...
1
vote
1answer
43 views

How to wrap REST API response with Wrapper object in Python Flask

While building REST API with flask-restful I'm getting unwanted json array in my response { "data": [ { "email": "sam@test.com", "id": null, "name": "...
0
votes
1answer
25 views

How to change the name of fields using SqlAlchemy-Marshmallow?

i'm using SQLAlchemy - Marshmallow for schema creation, it roughly looks like this: class someModel(db.Model): y_x = db.Column(db.BigInteger, primary_key = True) class someSchema(ma.ModelSchema): ...
0
votes
0answers
18 views

Marshmallow adding a calculated column during dump (deserialization)

Hello everyone : I have struggle with this for some time now. I have a Model as under: class Job(db.Model): __tablename__ ="job" id = db.Column(db.Integer, primary_key=True) title = db....
0
votes
0answers
34 views

serialize children in marshmallow-sqlalchemy

Marshmallow normally serializes nested children (assuming nested schema are defined). For example: { 'id': 2, 'messages' : [ { 'id': 1, 'message': 'foo' ...
3
votes
1answer
51 views

Is it possible to define a nested schema with mutually exclusive fields in marshmallow?

I am using marshmallow to validate json data that I am receiving in a flask restful api. In the post request however there is a mutually exclusive field. For example : {"predict": {"id": "5hgy667y4h7f"...
0
votes
1answer
20 views

SQLAlchemy - when to make extra models and relationships vs. just storing JSON in column?

I'm writing an app framework for a project, where each app is a set of functions. To describe these functions (parameter schemas, return schemas, plugin info, etc.) I'm using an OpenAPI 3.0-like ...
0
votes
1answer
84 views

Marshmallow deserializing fails when structure is nested

I am trying to deserialize a deep structure with marshmallow. For example: hour = { 'day': { 'name': 'monday' } } loaded_hour, error = HoursSerializationSchema().load(hour) # this ...
1
vote
1answer
34 views

JSON serialization using Marshmallow - skip None attributes

I am using Marshmallow to send instance of my Decision class to JSON. However, this will also dump the attributes which are None, e.g. my attribute score will translate to null in JSON. After that I ...
1
vote
1answer
44 views

Python marshmallow tree structure with polymorphism

I have the following code for a tree structure: class Node: def __init__(self, node_id: str): self.node_id = node_id self.children = [] def add_child(self, node: 'Node'): ...
0
votes
1answer
22 views

Nested class in JSON de-serialization using marshmallow

How would I de-serialize nested JSON using marshmallow so that I can use dot notation like app.data.person.lname? Currently my example works only one level down, but I can't get last name (lname) from ...
0
votes
1answer
20 views

Marshmallow - Sort field values by declared order

I've read the docs and searched this site but cannot seem to find a solution to sorting field values by the order in which they are declared. The docs state that adding ordered = True to the class ...
0
votes
0answers
46 views

How to include additional, unknown fields when loading data with marshmallow-mongoengine?

I am building a REST API on top of Flask and Connexion using marshmallow-mongoengine and MongoEngine to work with MongoDB. Problem: If my input data includes additional, unknown fields they are ...
0
votes
0answers
54 views

Using Marshmallow to serialize/deserialize with multiple formats

I have a Flask web service with a REST API with requests that expect a user to be serialized in a specific format. In addition, the web service interacts with a 3rd party service that expects the user ...
0
votes
0answers
57 views

python - marshmallow build Schema from jsonschema

Source of truth is a jsonschema file/string which I wish to utilise to build objects as using validations etc. Does Marshmallow allow to define schema using a JsonSchema rather than manually place ...
0
votes
1answer
103 views

SQLAlchemy LookupError: “DIVERSE” is not among the defined enum values

I'm trying to build simple REST API with single table with the help of SQLAlchemy, Marshmallow and flask-restplus. But it is giving LookupError. Following error is given by during the application ...
1
vote
1answer
56 views

Adding count of total rows through Marshmallow with @post_dump?

I need to add the quantity of rows returned in this query: queryPostgres = db.text(""" SELECT *, COUNT(*) OVER () as RowCount FROM ( SELECT * , ...
0
votes
2answers
34 views

How do I render one property object array to flat array in python flask sqlalchemy marshmallow app?

I am writing Python Flask WebApp first time. Using Flask, SQLAlchemy, Marshmallow as my primary packages. I have a nested schema, but in the parent page I am not displaying children, but I want to ...
1
vote
0answers
28 views

flask_marshmallow prevent loading new entities, but allow loading existing ones

Marshmallow schemas have a dump_only option which prevents deserializing things in that attribute during a load event. For example: class UserSerializationSchema(ma.ModelSchema): class Meta: ...
1
vote
1answer
34 views

Marshmallow serialization errors are empty even when validation fails

I'm adding marshmallow to my Python web service, mostly so that I can use the schemas to generate OpenAPI docs, but I'd also like the error checking on my API response serialization. I've read through ...
2
votes
1answer
38 views

'Missing data' when try to load data with data_key using marshmallow

I try to use marshmallow 2.18.0 on python 3.7 for validating data. I waiting for json {'name': 'foo', 'emailAddress': 'x@x.org'} and load it with schema: class FooLoad(Schema): name = fields.Str()...
0
votes
0answers
60 views

flask-marshmallow define schema to convert simple json to complex orm

I have some entities in sqlalchemy. They are User and messages which they sent UserMessage: class User(db.Model): __tablename__ ='User' email = Column(String) class UserMessage(db.Model): ...
0
votes
1answer
42 views

Testing a decorator that wraps api routes

I am building a rest api and I was making the routes for the api and stumbled upon a problem. I am using flask restplus to build the api and marshmallow to validate the json sent by the client. My ...
1
vote
1answer
57 views

Annotate an `exists` subquery in SQLAlchemy

I have a simple news app where users can see latest posts and they can like some of these posts. The models: from sqlalchemy.orm import relationship, backref from app import db class User(db.Model)...
0
votes
1answer
70 views

Related field not returned in marshmallow schema (also flask / sqlalchemy)

Using marshmallow 2.18.0, flask-marshmallow 0.9.0. I'm building a system which handles a series of questions and answers. The next question displayed depends on the answer to the previous question. ...
1
vote
2answers
44 views

Marshmallow Parent Schema - How to share a validation decorator between child schemas?

I have a parent marshmallow schema "ParentSchema" and 2 nested children schemas "ChildSchema1" and "ChildSchema2". Both nested children schemas are taking advantage of the @validates_schema decorator ...
1
vote
1answer
59 views

Writing Python POO. Marshmallow or Native Python. Which is the best way to create classes?

Being programming on python, i discovered marshmallow. I always create classes on native python . Is this library (or another) the best way to create POO based program ? import datetime as dt class ...
0
votes
1answer
125 views

SQLAlchemy - update an object with a transient object

I'm trying to use flask-rest-api as a framework for a simple example webservice with SQLAlchemy as the ORM. Everything works fine, except when dealing with updates. Here's the code in question: ...
0
votes
1answer
128 views

Nested Marshmallow and Sqlalchemy include children

I have a pivot (postgres)table that relates to 2 table. Using flask-marshmallow and sqlalchemy I want to fetch data from both tables from any of their marshmallow's schema. eg: Table1Schema().dump(...
0
votes
0answers
66 views

Foreign Key problem with sqlalchemy/marshmallow

I am trying to work on a RESTful example. I'm using Flask, marshmallow, sqlalchemy and a Postgres DB The problem is the FK in one table seems to be being treated like a field. I have tried googling ...
1
vote
1answer
70 views

How do I read the parameter of the GET request in a RESTful Flask/SQLAlchemy/Marshmallow environment

I was working my way through a couple of tutorials before xmas and I'm now trying to pick up where I left of. Trying to teach myself REST by building some simple API end points. My confusion is coming ...
1
vote
1answer
79 views

SQLAlchemy @property causes 'Unknown Field' error in Marshmallow with dump_only

I'm using flask-marshmallow (marshmallow=v3.0.0rc1, flask-marshmallow=0.9.0) and flask-sqlalchemy (sqlalchemy=1.2.16, flask-sqlalchemy=2.3.2) I have this model and schema. from marshmallow import ...
0
votes
1answer
58 views

Python Marshmallow not detecting error in required field

I am using marshmallow to validate the data of APIs. But, it is not working for required field. The following code works for length validation. password = fields.String(validate = validate.Length(...

http://mssss.yulina-kosm.ru