Fix @webapi_request_fields to properly check inherited fields.
Review Request #8981 — Created May 31, 2017 and submitted — Latest diff uploaded
The decorator for defining fields for webapi requests,
@webapi_request_fields
, was written to combine properly with
@augment_method_from
, allowing fields to be inherited. This can be seen in
the documentation for various resources, where the new fields are properly
combined with old ones. Unfortunately, the code that actually checks the fields
at runtime was using the wrong variable, causing it to only look at fields
defined in the most top-level method. We didn't notice this until now because
most places that use this also passallow_unknown=True
. This change fixes up
the decorator to check the combined fields lists.There's one complication added by the fact that if this decorator is applied
multiple times, the "inner" decorator doesn't know about the outer fields. I've
solved this by adding an assumption that if a field is present in kwargs, that
we've already parsed and validated its contents.
- Reproduced a regression in Review Board 2.5.10 which was caused by the
addition of a fields decorator in a subclass that shadowed parameters from
the superclass. After this change, I was once again able to use the
max-results
andstart
parameters that had been hidden. - Ran unit tests.