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

Endpoint arguments are masked by caller arguments #125

Open
ryneeverett opened this issue Jan 26, 2023 · 0 comments
Open

Endpoint arguments are masked by caller arguments #125

ryneeverett opened this issue Jan 26, 2023 · 0 comments
Labels
✨ enhancement New feature or request

Comments

@ryneeverett
Copy link

Describe the bug
If an endpoint argument is given the same name as an argument to apiron.client.call, it will not be passed through to the formatter.

To Reproduce

>>> from apiron import JsonEndpoint, Service
>>> class GitHub(Service):
    ...     domain = 'https://api.github.com'
    ...     user = JsonEndpoint(path='/users/{method}')
    ...
>>> response = GitHub.user(method='defunkt')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/apiron/src/apiron/client.py", line 238, in call
    request = _build_request_object(
  File "/apiron/src/apiron/client.py", line 112, in _build_request_object
    path = endpoint.get_formatted_path(**kwargs)
  File "/apiron/src/apiron/endpoint/endpoint.py", line 127, in get_formatted_path
    return self.path.format(**kwargs)
KeyError: 'method'

Expected behavior
The simplest improvement would be if endpoints raised an exception when such collisions occur. This way there would be a better error message at evaluation time rather than a less clear exception when the endpoint is called.

Really though, apiron should be restructured so that kwargs passed into an endpoint aren't intermingled with those passed to apiron.client.call.

Environment:

  • OS: linux
  • Python version 3.10.7
  • apiron version 7d1d059
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants