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

using uplink.Url results in an AttributeError #164

Closed
cognifloyd opened this issue Jun 16, 2019 · 1 comment · Fixed by #165
Closed

using uplink.Url results in an AttributeError #164

cognifloyd opened this issue Jun 16, 2019 · 1 comment · Fixed by #165
Milestone

Comments

@cognifloyd
Copy link
Contributor

Describe the bug
Attempting to use uplink.Url results in an AttributeError.

...
    return self._check_async_results(future_response.location)
  File "/home/cognifloyd/v/st2/lib/python2.7/site-packages/uplink/builder.py", line 99, in __call__
    self._request_definition.define_request(request_builder, args, kwargs)
  File "/home/cognifloyd/v/st2/lib/python2.7/site-packages/uplink/commands.py", line 271, in define_request
    request_builder.url = request_builder.url.build()
AttributeError: 'str' object has no attribute 'build'

To Reproduce
Use uplink.Url as an argument and provide a string with a full URL.

Expected behavior
A clear and concise description of what you expected to happen.
No error.

Additional context
It looks like

  • commands.py line 265: request_builder.Url is set to an instance of uplink.utils.URIBuilder
  • commands.py line 267: eventually calls uplink.Url._modify_request()
    • arguments.py line 682: replace request_builder.Url with the final string
  • commands.py line 271: calls request_builder.url.build() assuming that it is still a URIBuilder instance.

uplink/uplink/commands.py

Lines 263 to 271 in 8483dcc

def define_request(self, request_builder, func_args, func_kwargs):
request_builder.method = self._method
request_builder.url = utils.URIBuilder(self._uri)
request_builder.return_type = self._return_type
self._argument_handler.handle_call(
request_builder, func_args, func_kwargs
)
self._method_handler.handle_builder(request_builder)
request_builder.url = request_builder.url.build()

uplink/uplink/arguments.py

Lines 680 to 682 in 0d29483

def _modify_request(cls, request_builder, value):
"""Updates request url."""
request_builder.url = value

So, maybe what's needed is:

def define_request(...):
    ...
    self._argument...
    self._method...
    if isinstance(request_builder.url, utils.URIBuilder):
        request_builder.url = request_builder.url.build() 
@cognifloyd
Copy link
Contributor Author

I just tested, and my recommended fix does work. I'll submit a PR momentarily. I don't know if there's a better way to fix this.

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 a pull request may close this issue.

2 participants