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

fix list field accept dict parameter bug #597

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Friday21
Copy link

when I use List field with nested object field, I find out when the client pass the object filed(not as list), the parameter check didn't throw parameter error(400), so I got a json object in my view layer, that is not what I expected, thus trigger a bug。

@coveralls
Copy link

Coverage Status

Coverage increased (+0.002%) to 96.847% when pulling 0b567d4 on Friday21:master into a8f3582 on noirbizarre:master.

@SteadBytes
Copy link
Collaborator

Thanks for contributing! Could you please provide some example code to reproduce the issue in the same way you encountered it?

@Friday21
Copy link
Author

Thanks for contributing! Could you please provide some example code to reproduce the issue in the same way you encountered it?

I think the test case I add in test_format_error has already include one example

@SteadBytes
Copy link
Collaborator

SteadBytes commented Mar 31, 2019

I see the test case (thank you for that), however it's not a full example of the use case that you described. Calling the format method on a field directly is very different to how it is used when receiving a POST payload

@Friday21
Copy link
Author

I see the test case (thank you for that), however it's not a full example of the use case that you described. Calling the format method on a field directly is very different to how it is used when receiving a POST payload

OK, so here is my example in real project(change some name to hide work info):

first, the input model definition:

time_fields = api.model('TimeInput', {
    'id': fields.Integer(required=True, description='ID'),
    'time_area_list': fields.List(fields.List(fields.Integer), required=True,
                                  description='time area, ex: [[t1, t2], [t3, t4], [t5], [t6, t7]...]')
})

test_list_fields = api.model('TimelistInput', {
    'list_time': fields.List(fields.Nested(time_fields), required=True),
})

and, here is the code in the rest api code:

@time_api.route('/beat', methods=['POST', 'PUT'])
class TimeResource(Resource):
    @time_api.expect(input.test_list_fields)
    def post(self):
        """"""
        payload = self.api.payload
        time_list = payload.get('list_time')
        print(time_list)
        return response(ResponseCode.SUCCESS, msg='success')

and then, I send request through postman with list_time field as list of object

Screen Shot 2019-03-31 at 10 21 01 PM

this works as expected. then I send list_time field as object:

Screen Shot 2019-03-31 at 10 21 46 PM

it should have return parameter error, but it didn't, it just pass on. the print info is below:

Screen Shot 2019-03-31 at 10 22 16 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants