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

Confusing exception with GET methods and request bodies #126

Open
inklesspen opened this issue Nov 29, 2017 · 13 comments
Open

Confusing exception with GET methods and request bodies #126

inklesspen opened this issue Nov 29, 2017 · 13 comments
Assignees

Comments

@inklesspen
Copy link
Contributor

If a method is defined with http_method GET and the method has a message or resource container as the request body, and that request body has fields which aren't in the resource container, a strange and confusing exception arises.

Repro by cloning https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/appengine/standard/endpoints-frameworks-v2/echo/main.py and changing 'POST' to 'GET'

    descriptor = self.get_openapi_dict(services, hostname)
  File "/usr/local/google/home/rhd/appflex/python-docs-samples/appengine/standard/endpoints-frameworks-v2/echo/lib/endpoints/openapi_generator.py", line 1011, in get_openapi_dict
    return self.__api_openapi_descriptor(services, hostname=hostname)
  File "/usr/local/google/home/rhd/appflex/python-docs-samples/appengine/standard/endpoints-frameworks-v2/echo/lib/endpoints/openapi_generator.py", line 915, in __api_openapi_descriptor
    security_definitions)
  File "/usr/local/google/home/rhd/appflex/python-docs-samples/appengine/standard/endpoints-frameworks-v2/echo/lib/endpoints/openapi_generator.py", line 726, in __method_descriptor
    path)
  File "/usr/local/google/home/rhd/appflex/python-docs-samples/appengine/standard/endpoints-frameworks-v2/echo/lib/endpoints/openapi_generator.py", line 589, in __request_message_descriptor
    method_id)
  File "/usr/local/google/home/rhd/appflex/python-docs-samples/appengine/standard/endpoints-frameworks-v2/echo/lib/endpoints/openapi_generator.py", line 543, in __params_descriptor
    params.append(self.__body_parameter_descriptor(method_id))
  File "/usr/local/google/home/rhd/appflex/python-docs-samples/appengine/standard/endpoints-frameworks-v2/echo/lib/endpoints/openapi_generator.py", line 365, in __body_parameter_descriptor
    self.__request_schema[method_id])
KeyError: 'echo.echo'
@inklesspen inklesspen self-assigned this Nov 29, 2017
@inklesspen
Copy link
Contributor Author

@kryzthov Recording the issue you found so it can be improved.

@danierdev
Copy link

I have the same error using endpoints_proto_datastore

@Bicycle.method(request_fields=('id',),
                path='bikes/{id}', http_method='GET',
                name='bikes.get')
    def bikes_get(self, bike):
        if not bike.from_datastore:
            raise endpoints.NotFoundException('Bicycle (%s) not found.' % (bike.id,))
        return bike

Error

Traceback (most recent call last):
  File "lib/endpoints/endpointscfg.py", line 31, in <module>
    main(sys.argv)
  File "C:\Users\Danier\Projects\bikestore\lib\endpoints\_endpointscfg_impl.py", line 634, in main
    args.callback(args)
  File "C:\Users\Danier\Projects\bikestore\lib\endpoints\_endpointscfg_impl.py", line 487, in _GenOpenApiSpecCallback
    application_path=args.application)
  File "C:\Users\Danier\Projects\bikestore\lib\endpoints\_endpointscfg_impl.py", line 332, in _GenOpenApiSpec
    application_path=application_path)
  File "C:\Users\Danier\Projects\bikestore\lib\endpoints\_endpointscfg_impl.py", line 214, in GenApiConfig
    services, hostname=hostname))
  File "C:\Users\Danier\Projects\bikestore\lib\endpoints\openapi_generator.py", line 1028, in pretty_print_config_to_json
    descriptor = self.get_openapi_dict(services, hostname)
  File "C:\Users\Danier\Projects\bikestore\lib\endpoints\openapi_generator.py", line 1014, in get_openapi_dict
    return self.__api_openapi_descriptor(services, hostname=hostname)
  File "C:\Users\Danier\Projects\bikestore\lib\endpoints\openapi_generator.py", line 918, in __api_openapi_descriptor
    security_definitions)
  File "C:\Users\Danier\Projects\bikestore\lib\endpoints\openapi_generator.py", line 729, in __method_descriptor
    path)
  File "C:\Users\Danier\Projects\bikestore\lib\endpoints\openapi_generator.py", line 592, in __request_message_descriptor
    method_id)
  File "C:\Users\Danier\Projects\bikestore\lib\endpoints\openapi_generator.py", line 546, in __params_descriptor
    params.append(self.__body_parameter_descriptor(method_id))
  File "C:\Users\Danier\Projects\bikestore\lib\endpoints\openapi_generator.py", line 367, in __body_parameter_descriptor
    self.__request_schema[method_id])
KeyError: 'bikestore.bikes.get'

@inklesspen
Copy link
Contributor Author

endpoints_proto_datastore is not a supported project, but I do intend to fix the original issue soon.

@winsomniak
Copy link
Contributor

Hi @inklesspen

I can confirm the issue with endpoints_proto_datastore yielding the key error. Easily reproduced by following the simple_get example. We spent a bunch of time troubleshooting this and another issue related to custom ndb properties before deciding to use endpoints framework directly.

While I can appreciate that endpoints_proto_datastore is not an official part of endpoints, it is promoted directly from the from the docs.

Not sure who maintains the site, but it would probably save people time and frustration to make a note of current issues or remove the recommendation.

Cheers

@tolsac
Copy link

tolsac commented May 15, 2018

I have exactly the same problem .. any improvement soon ?

@inklesspen
Copy link
Contributor Author

There is a workaround; do not have request body fields in GET requests.

@truepants
Copy link

We also have exactly the same problem. So you suggest as a workaround change al GET request to POST requests? For a temporary workaround in development it will be sufficient, but for production it's a no-go for my team. Is it likely to be resolved soon?

@tangiel
Copy link
Contributor

tangiel commented May 30, 2018

Can you explain why is this a no go for your team?

@inklesspen
Copy link
Contributor Author

GET requests are not supposed to have request bodies.

@truepants
Copy link

Well maybe I don't understand it correctly. I have a annotation like:
@ExampleModel.method(
request_fields=('playerId',),
path='example/stats/{playerId}',
http_method='GET',
name='example.stats',
user_required=True)

When I generate the openapi spec I get KeyError: 'api.example.stats'. Did I do something wrong?

@inklesspen
Copy link
Contributor Author

@truepants, that would be a different problem entirely; this issue is about exceptions that occur while handling GET requests that contain request bodies.

Please open a new issue with your full traceback and the code which reproduces it, and I can have a look.

@inklesspen
Copy link
Contributor Author

However please note that endpoints_proto_datastore is not supported by this team.

@truepants
Copy link

Thanks for the quick response. I will create a new issue.

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

No branches or pull requests

6 participants