Skip to content
  • Deimos's avatar
    Upgrade webargs to 6.1.0 · f41bd1ea
    Deimos authored
    This was not a fun upgrade. webargs made some major changes to its
    approaches in 6.0, which are mostly covered here:
    https://webargs.readthedocs.io/en/latest/upgrading.html
    
    To keep using it on Tildes, this commit had to make the following
    changes:
    
      - Write my own wrapper for use_kwargs that changes some of the default
        behavior. Specifically, we want the location that data is being
        loaded from to default to "query" (the query string) instead of
        webargs' default of "json". We also needed to set the "unknown"
        behavior on every schema to "exclude" so that the schemas would
        ignore any data fields they didn't need, since the default behavior
        is to throw an error, which happens almost everywhere because of
        Intercooler variables and/or multiple use_kwargs calls for different
        subsets of the data.
    
      - All @pre_load hooks in schemas needed to be rewritten so that they
        weren't modifying data in-place (copy to a new data dict first).
        Because webargs is now passing all data through all schemas,
        modifying in-place could result in an earlier schema modifying data
        that would then be passed in modified form to the later ones.
        Specifically, this caused an issue with tags on posting a new topic,
        where we just wanted to treat the tags as a string, but TopicSchema
        would convert it to a list in @pre_load.
    
      - use_kwargs on every endpoint using non-query data needed to be
        updated to support the new single-location approach, either replacing
        an existing locations= with location=, or adding location="form",
        since form data was no longer used by default.
    
      - The code that parsed the errors returned by webargs/Marshmallow
        ValidationErrors needed to update to handle the additional "level"
        in the dict of errors, where errors are now split out by location
        and then field, instead of only by field.
    
      - A few other minor updates, like always passing a schema object
        instead of a class, and never passing a callable (mostly just for
        simplicity in the wrapper).
    f41bd1ea