Questions tagged [flask-marshmallow]

106 questions
2
votes
2 answers

How can I load only a foreign key into Nested fields using Marshmallow / SQLAlchemy

I'm very new to Flask-Marshmallow / Flask-SQLAlchemy and I'm trying to set up my own REST API with flask and mysql. Here is the payload I'm trying to post. I want to be able to only send the ID and exclude all other fields: { "code": "FG034", …
myko324
  • 21
  • 3
2
votes
2 answers

Call marshmallow validated GET endpoint with List parameter

I have a marshmallow schema validation like this: class MyFilterSchema(Schema): ids = fields.List(fields.Str(validate=non_empty), required=True) Then in my endpoint I call the schema validation:…
Eisen
  • 115
  • 2
  • 12
2
votes
1 answer

Many to Many relationship Flask sqlalchemy and marshmallow

Suppose i have 2 tables , Table 1 consist of users info and Table 2 consist of Branch info. table 1 and table 2 is related to each other by many to many relationship. e.g 1 user can work in multiple branches and 1 branch can have multiple users. so…
2
votes
0 answers

How to group fields when serialising object with Marshmallow?

Problem How to group fields together when serialising a flat-structured SQLAlchemy object with Marshmallow without changing the flat data structure in the background? Example Suppose a SQLAlchemy model in a Flask app like this: from app import db #…
2
votes
1 answer

TypeError: _deserialize() got an unexpected keyword argument 'partial' in marshmallow

I'm trying image upload API i'm getting the following error 127.0.0.1 "POST //upload/image HTTP/1.1" 500 - Traceback (most recent call last): File "D:\c_code\projects\python_api\.venv\lib\site-packages\flask\app.py", line 2463, in __call__ …
Himavan
  • 385
  • 3
  • 16
2
votes
1 answer

Deserialize list of ids for many-to-many PUT operation

I have a User and Role model with a many-to-many relationship class User(BaseModel, TimestampableMixin): username = Column(String(MEDIUM_STRING_LENGTH), nullable=False, unique=True) roles = relationship('Role', secondary='user_roles',…
1
vote
1 answer

Marshmallow Date Validation

I have written a validation for the input that I receive but now the issue is that i have mentioned a type as date and whenever the date is empty I receive it as "". So is there any way that I can skip validation if input is ""? My…
1
vote
1 answer

How to get marshmallow to give out a List of nested classes with 1 entry pulled out

I am trying to get flask-marshmallow to give me a list of translated entries from a Table called Type that is associated to a table called Language. I cannot figure out how to nest the responses in a list. I gave an example of my current output JSON…
1
vote
3 answers

Flask jsonify returns Response. How to provide status code?

I sow a lot of examples where developers have the following expression: return jsonify(data), 200 Even in my last work project I had the same expression, but now, when I'm trying to write my new project, I catch the following error: TypeError:…
1
vote
0 answers

Python: marshmallow doesn't return backref column data

I have two tables as below where SupplierCompany has a relationship with Office and has a backref column referenced in the Office table: class Office(BaseModel): __tablename__ = 'offices' id = db.Column(db.Integer, primary_key=True) …
1
vote
1 answer

Getting foreign key instead of relationship table in marshmallow_sqlalchemy schema

I have a flask-sqlalchemy table composed of a relationship with 4 other tables as follows: office_cardgroups = db.Table('office_cardgroups', db.Column('officedata_id', db.Integer, db.ForeignKey('officedata.id')), …
1
vote
0 answers

TypeError: execute_values() got an unexpected keyword argument 'fetch'

I am having an issue with creating an entry into a many-to-many postgresql db table with Flask, Flask-sqlalchemy, and flask-marshmallow. Below are my model setups. role_permissions = db.Table( 'role_permissions', db.Column('id', db.Integer,…
1
vote
0 answers

Flask sqlalchemy Marshmallow deserialize many to many 'dict' object has no attribute '_sa_instance_state'

I'm trying to user marshmallow's .load() method to deserialize a json object on a POST request. But I keep running into this error 'dict' object has no attribute '_sa_instance_state' Users and Roles has a many to many relationship. .dump() on the…
RuSs
  • 769
  • 2
  • 12
  • 27
1
vote
1 answer

marshmallow - include_fk fail if foreign_key is not int

On serializing a related database entity with sql-alchemy and marshmallow I encountered following issue: On dumping this schema the debugger raises a ValueError with the message self._serialize(d, many=False) value =…
1
vote
1 answer

How to input array of strings with Flask + Swagger UI?

I have a flask api that automatically validates and generates Swagger documentation thanks to marshmallow package. One of the API methods is a POST request that wants a specific id as a string and a list_of_ids as an array of strings. The GUI looks…
purple_lolakos
  • 456
  • 5
  • 15