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

Uploaded file not passed to endpoints taking kwargs #750

Closed
simenaasland opened this issue Nov 6, 2018 · 4 comments
Closed

Uploaded file not passed to endpoints taking kwargs #750

simenaasland opened this issue Nov 6, 2018 · 4 comments

Comments

@simenaasland
Copy link

simenaasland commented Nov 6, 2018

Description

I am not 100% sure this should be considered a bug, but the behavior has changed between 1.2.0 and 2.0.0, so it might be a regression. Uploaded files are only passed as arguments to endpoints not taking kwargs in version 2.0.0.

Expected behaviour

When uploading a file, the file should always be passed as a parameter to the endpoint.

Actual behaviour

When uploading a file, the file is only passed to endpoints not taking kwargs.

Steps to reproduce

flask 1.0.2
requests 2.20.0
connexion 1.2.0 and 2.0.0

api.yaml:

swagger: '2.0'
info:
  version: '1'
  title: File Upload

paths:
  /upload:
    post:
      operationId: app.upload
      consumes:
        - multipart/form-data
      parameters:
        - in: formData
          name: upload_file
          type: file
          required: false
      responses:
        '200':
          description: OK
        '400':
          description: Bad request.
        default:
          description: Error

app.py:

def upload(upload_file=None, **kwargs):
    if upload_file is None:
        return "Did not get file as arg"
    return "Got file as arg"

Run application and send request:

connexion run api.yaml
python -c 'import requests; print requests.post("http://localhost:5000/upload", files=dict(upload_file="test")).text'

Response with connexion 1.2.0: Got file as arg
Response with connexion 2.0.0: Did not get file as arg

This seems to be the relevant change since 1.2.0:

https://github.com/zalando/connexion/blob/44ea9336fe79ddb9592942b405a663d2e3aa612c/connexion/operations/abstract.py#L169-L171

Additional info:

Output of the commands:

  • python --version: Python 2.7.15rc1
  • pip show connexion | grep "^Version\:": Version: 2.0.0
@dtkav
Copy link
Collaborator

dtkav commented Nov 6, 2018

Thanks for taking the time to file this ticket. That definitely sounds like a bug to me!

@dtkav
Copy link
Collaborator

dtkav commented Nov 6, 2018

@simenaasland please have a look at #753 - I think it should fix the issue.

@simenaasland
Copy link
Author

@dtkav Thanks a lot for looking at this so quickly! The fix looks good to me. Do you want me to comment and/or approve in the PR itself?

@dtkav
Copy link
Collaborator

dtkav commented Nov 6, 2018 via email

@jmcs jmcs closed this as completed in #753 Nov 7, 2018
jmcs pushed a commit that referenced this issue Nov 7, 2018
- pass file if filename in arguments _or_ has_kwargs (Fixes #750)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants