ihiji / falcon-marshmallow Goto Github PK
View Code? Open in Web Editor NEWMarshmallow serialization/deserialization middleware for Falcon
License: MIT License
Marshmallow serialization/deserialization middleware for Falcon
License: MIT License
I would like to not display marshmallow logs. Is that possible?
Have you considered changing the API to expose a get_schema
callable so you could return different schema instances dynamically? This would be useful, for example, if someone had different users permissioned for different things accessing the same endpoint. You might want to use different schemas depending on their permissions.
Set up a Jenkins user, config, & job to push this out to both our servers & PyPI, since we're open sourcing it.
When doing a POST with invalid data I get a
HTTP/1.1 200 OK
Connection: keep-alive
Content-Encoding: gzip
Content-Type: application/json; charset=UTF-8
Date: Tue, 12 Dec 2017 20:34:35 GMT
Keep-Alive: timeout=10
Server: nginx
Strict-Transport-Security: max-age=31536000
Transfer-Encoding: chunked
Vary: Accept-Encoding
X-Content-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
{
"error": {
"code": 500,
"msg": "Something went wrong"
}
}
And the internal server error is
web_1 | [2017-12-12 20:34:35,370 controlpanel.server ERROR 1fe9260230bb8a7db417be6bb2c15cdc] {'user_script': ['Missing data for required field.'], 'title': ['Missing data for required field.']}
web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/lib/python3.6/site-packages/falcon/api.py", line 240, in __call__
web_1 | process_resource(req, resp, resource, params)
web_1 | File "/usr/local/lib/python3.6/site-packages/falcon_marshmallow/middleware.py", line 300, in process_resource
web_1 | data, errors = sch.load(parsed)
web_1 | File "/usr/local/lib/python3.6/site-packages/marshmallow/schema.py", line 580, in load
web_1 | result, errors = self._do_load(data, many, partial=partial, postprocess=True)
web_1 | File "/usr/local/lib/python3.6/site-packages/marshmallow/schema.py", line 701, in _do_load
web_1 | raise exc
web_1 | marshmallow.exceptions.ValidationError: {'user_script': ['Missing data for required field.'], 'title': ['Missing data for required field.']}
web_1 | [2017-12-12 20:34:35,377 SERVER INFO 1fe9260230bb8a7db417be6bb2c15cdc] END POST /v1/user-scripts
web_1 | [pid: 8|app: 0|req: 1/1] 172.21.0.4 () {46 vars in 801 bytes} [Tue Dec 12 20:34:35 2017] POST /v1/user-scripts => generated 55 bytes in 53 msecs (HTTP/1.0 200) 2 headers in 86 bytes (1 switches on core 0)
But the documentation says this should happen:
"When parsing a request body, if it cannot be decoded or its JSON is malformed, an HTTPBadRequest error will be raised. If the deserialization of the request body fails due to schema validation errors, an HTTPUnprocessableEntity error will be raised."
What am I doing wrong?
/2023 17:02:33] "POST /api/workouts HTTP/1.1" 500 -
[2023-03-07 17:03:04,784] ERROR in app: Exception on /api/workouts [POST]
Traceback (most recent call last):
File "/Users/ansi/Desktop/PROJECTS/journeybackend/env/lib/python3.10/site-packages/flask/app.py", line 1823, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/ansi/Desktop/PROJECTS/journeybackend/env/lib/python3.10/site-packages/flask/app.py", line 1799, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
File "/Users/ansi/Desktop/PROJECTS/journeybackend/env/lib/python3.10/site-packages/flask_restful/init.py", line 467, in wrapper
resp = resource(*args, **kwargs)
File "/Users/ansi/Desktop/PROJECTS/journeybackend/env/lib/python3.10/site-packages/flask/views.py", line 107, in view
return current_app.ensure_sync(self.dispatch_request)(**kwargs)
File "/Users/ansi/Desktop/PROJECTS/journeybackend/env/lib/python3.10/site-packages/flask_restful/init.py", line 582, in dispatch_request
resp = meth(*args, **kwargs)
File "/Users/ansi/Downloads/journeybackend-main/routes.py", line 178, in post
workout_data = workout_schema.load(workout_json)
File "/Users/ansi/Desktop/PROJECTS/journeybackend/env/lib/python3.10/site-packages/marshmallow_sqlalchemy/load_instance_mixin.py", line 96, in load
return super().load(data, **kwargs)
File "/Users/ansi/Desktop/PROJECTS/journeybackend/env/lib/python3.10/site-packages/marshmallow/schema.py", line 722, in load
return self._do_load(
File "/Users/ansi/Desktop/PROJECTS/journeybackend/env/lib/python3.10/site-packages/marshmallow/schema.py", line 909, in _do_load
raise exc
marshmallow.exceptions.ValidationError: {'total_time': ['Missing data for required field.'], 'total_time ': ['Unknown field.']}
192.168.206.79 - - [07/Mar/2023 17:03:04] "POST /api/workouts HTTP/1.1" 500 -
Great library!
I like the convention of {method}_schema
to specify different schemas for different HTTP methods. What about optionally extending that idea to allow different schemas for the request & response of the same method? Perhaps something like {method}_{req_or_resp}_schema
. I can submit a PR if you like.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.