GithubHelp home page GithubHelp logo

falcon-marshmallow's People

Contributors

daemonburrito avatar mplanchard avatar timc13 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

falcon-marshmallow's Issues

callable get_schema?

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.

Jenkins Job to Push to PyPI

Set up a Jenkins user, config, & job to push this out to both our servers & PyPI, since we're open sourcing it.

Validation errors appear as Marshmallow Exceptions and don't get raised as http errors

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?

i got this problem in flask

/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 -

Different schema for request & response

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.