Skip to content
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

Pass all args to schemas, but default to unknown=EXCLUDE (work in progress) #410

Closed
wants to merge 3 commits into from

Commits on Aug 4, 2019

  1. Initial work on passing all args to schemas

    If Parser.pass_all_args is set (it defaults to false for backwards
    compatibility), then argument parsing becomes a two step process.
    First, args are parsed based on the schema fields, as today. Then,
    second, they are all treated as marshmallow.fields.Raw , parsed by
    webargs , and then passed to the schema for validation.
    
    If Parser.pass_all_args is set on marshmallow versions < 3, it is a
    ValueError.
    
    In order to collect arguments to pass to the schema, adds a new
    function required on all parsers, get_args_by_location , which collects
    all argument names, typically dict keys, categorized by location name.
    This is only implemented here in the flask parser, as a proof of
    concept.
    sirosen committed Aug 4, 2019
    Configuration menu
    Copy the full SHA
    4ced01f View commit details
    Browse the repository at this point in the history
  2. Convert Parser.pass_all_args to Parser.unknown

    This commit is an intermediate step meant to show the distinction
    between a standalone pass_all_args flag and *always* passing all args
    but allowing the user to specify a value for `unknown` to pass to
    `Schema.load()`.
    
    In this version, the webargs.Parser object is able to use
    `Schema.load(unknown=EXCLUDE)` on marshmallow 3 as the default for
    backwards compatibility. Users can pass `unknown=None` to specify that
    the Parser should not pass a value and the schema default should be
    used. In this way, the backwards-incompatible change to be made in a
    future webargs release will be to change the default for
    Parser.unknown from EXCLUDE to None (or to eliminate it, and make the
    `None` behavior the only option).
    sirosen committed Aug 4, 2019
    Configuration menu
    Copy the full SHA
    52bab64 View commit details
    Browse the repository at this point in the history

Commits on Aug 8, 2019

  1. Implement get_args_by_location for all parsers

    Add implementations of this method for all existing parsers. For the
    most part, the pattern is quite simple and nearly identical. Usually,
    JSON data-loading needs to be moved into a helper for use both in
    get_arbs_by_location and parse_json.
    
    The asyncparser is particularly significant, as it reimplements much of
    the core parser in order to make get_args_by_location an async
    (awaitable) method.
    sirosen committed Aug 8, 2019
    Configuration menu
    Copy the full SHA
    eeb1efb View commit details
    Browse the repository at this point in the history