-
-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use marshmallow under the hood #61
Comments
This seems like a good solution to me. On Mon, Sep 21, 2015 at 9:26 AM, Steven Loria notifications@github.com
|
+1 |
Making lots of progress on this. I haven't yet decided where fields should be imported from. Here are the alternatives (note that (1) Import from from webargs import fields
from webargs.flaskparser import use_args
from marshmallow import validate
@use_args({
'data': fields.Nested({
'id': fields.Int(),
'email': fields.Str(validate=validate.Email()),
})
}) (2) Import from import webargs as wa
from webargs.flaskparser import use_args
from marshmallow import validate
@use_args({
'data': wa.Nested({
'id': wa.Int(),
'email': wa.Str(validate=validate.Email()),
})
}) (3) Import from from webargs import Nested # or from webargs.fields import Nested
from webargs.flaskparser import use_args
from marshmallow import fields, validate
@use_args({
'data': Nested({
'id': fields.Int(),
'email': fields.Str(validate=validate.Email()),
})
}) Any preferences? |
On Tue, Sep 22, 2015 at 2:51 PM, Steven Loria notifications@github.com
|
Fair point. On the other hand, perhaps we don't want to "leak" the marshmallow abstraction? As a user, I don't really like being required to import a 3rd-party library's (marshmallow) modules in the common case, but that's personal preference. |
From discussion with @jmcarp : "I think i prefer 1 or 2 just so it's harder to use the wrong |
I would argue that you shouldn't import from Marshmallow at all. If you want to use Marshmallow under the good, go all the way.
|
To play devil's advocate: there's a risk of hiding too much. If users import That said, I think importing |
There's also an argument for future-proofing: we can always add imports to webargs without breaking backwards-compat; we cannot remove them without breaking compat. |
The |
👍 |
This adds a custom `Date` field which respects `settings.TIMEZONE`. This also exposes elasticsearch_dsl's fields from the top-level module, so that all fields are imported from the same place: ```python from elasticsearch_metrics import Keyword, Date ``` This approach was the same used in webargs, which uses marshmallow fields under the hood but overrides a single field. Discussion: marshmallow-code/webargs#61 (comment) close #18
This adds a custom `Date` field which respects `settings.TIMEZONE`. This also exposes elasticsearch_dsl's fields from the top-level module, so that all fields are imported from the same place: ```python from elasticsearch_metrics import Keyword, Date ``` This approach was the same used in webargs, which uses marshmallow fields under the hood but overrides a single field. Discussion: marshmallow-code/webargs#61 (comment) close #18
This adds a custom `Date` field which respects `settings.TIMEZONE`. This also exposes elasticsearch_dsl's fields from the top-level module, so that all fields are imported from the same place: ```python from elasticsearch_metrics import Keyword, Date ``` This approach was the same used in webargs, which uses marshmallow fields under the hood but overrides a single field. Discussion: marshmallow-code/webargs#61 (comment) close #18
This adds a custom `Date` field which respects `settings.TIMEZONE`. This also exposes elasticsearch_dsl's fields from the metrics module, so that all fields are imported from the same place: ```python from elasticsearch_metrics import Keyword, Date ``` This approach was the same used in webargs, which uses marshmallow fields under the hood but overrides a single field. Discussion: marshmallow-code/webargs#61 (comment) close #18
This adds a custom `Date` field which respects `settings.TIMEZONE`. This also exposes elasticsearch_dsl's fields from the metrics module, so that all fields are imported from the same place: ```python from elasticsearch_metrics import Keyword, Date ``` This approach was the same used in webargs, which uses marshmallow fields under the hood but overrides a single field. Discussion: marshmallow-code/webargs#61 (comment) close #18
This adds a custom `Date` field which respects `settings.TIMEZONE`. This also exposes elasticsearch_dsl's fields from the metrics module, so that all fields are imported from the same place: ```python from elasticsearch_metrics import metrics class MyMetric(metrics.Metric): my_keyword = metrics.Keyword() my_date = metrics.Date() ``` This approach was the same used in webargs, which uses marshmallow fields under the hood but overrides a single field. Discussion: marshmallow-code/webargs#61 (comment) close #18
This adds a custom `Date` field which respects `settings.TIMEZONE`. This also exposes elasticsearch_dsl's fields from the metrics module, so that all fields are imported from the same place: ```python from elasticsearch_metrics import metrics class MyMetric(metrics.Metric): my_keyword = metrics.Keyword() my_date = metrics.Date() ``` This approach was the same used in webargs, which uses marshmallow fields under the hood but overrides a single field. Discussion: marshmallow-code/webargs#61 (comment) close #18
This adds a custom `Date` field which respects `settings.TIMEZONE`. This also exposes elasticsearch_dsl's fields from the metrics module, so that all fields are imported from the same place: ```python from elasticsearch_metrics import metrics class MyMetric(metrics.Metric): my_keyword = metrics.Keyword() my_date = metrics.Date() ``` This approach was the same used in webargs, which uses marshmallow fields under the hood but overrides a single field. Discussion: marshmallow-code/webargs#61 (comment) close #18
This adds a custom `Date` field which respects `settings.TIMEZONE`. This also exposes elasticsearch_dsl's fields from the metrics module, so that all fields are imported from the same place: ```python from elasticsearch_metrics import metrics class MyMetric(metrics.Metric): my_keyword = metrics.Keyword() my_date = metrics.Date() ``` This approach was the same used in webargs, which uses marshmallow fields under the hood but overrides a single field. Discussion: marshmallow-code/webargs#61 (comment) close #18
Proposal
Replace
Arg
objects with marshmallow fields. Use marshmallow for validation.Why?
Webargs and marshmallow have redundant functionality for validating input data against a user-defined schema. Marshmallow does a better job of than webargs in a number of respects:
Nested
field would solve allow_missing=False not working with nested args #39 and allow_missing=True not working with nested args on passing null #51.Proposed API
The text was updated successfully, but these errors were encountered: