Skip to content

Conversation

@btimby
Copy link

@btimby btimby commented Mar 3, 2017

I think these changes make things more explicit. I chose to preserve old functionality with warnings rather than outright remove them.

All of the old functionality can be achieved through the use of auto_refresh_kwargs, the preferred explicit method.

I have not yet tested this in my codebase, but the old and new tests all pass. I added some missing tests for old functionality as well as tests for the new stuff.

@coveralls
Copy link

coveralls commented Mar 3, 2017

Coverage Status

Coverage decreased (-0.09%) to 86.902% when pulling eee296a on btimby:master into a618145 on requests:master.

@coveralls
Copy link

coveralls commented Mar 3, 2017

Coverage Status

Coverage decreased (-0.04%) to 86.957% when pulling fd7eaa5 on btimby:master into a618145 on requests:master.

Copy link
Member

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, this sounds great so far! I have a few notes but at a high level this seems like it's in really good shape. Thanks for this!

old_showwarning(message, category, filename, lineno, file=file)

# Install our new handler.
warnings.showwarning = logwarning
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am very nervous about monkeypatching the warnings module. I'd rather not do it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but it is still unnecessary for us to do this. We can just use a regular function, rather than change global state.

log.debug('Adding auto refresh key word arguments %s.',
self.auto_refresh_kwargs)
kwargs.update(self.auto_refresh_kwargs)
log.debug('Kwargs: %s', kwargs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This log message isn't really useful anymore: it might be better to remove it rather than leave it like this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that is a leftover, will remove it.

"""Intercept all requests and add the OAuth 2 token if present."""
if not is_secure_transport(url):
raise InsecureTransportError()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not add random changes. 😊

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI... it was not "random" I was trying to make it more readable... Nevertheless the whitespace is removed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Legibility changes are fine, but they're better in seaparate PRs so that I can keep track of what is going on

# Start with kwargs explicitly requested for refresh.
refresh_kwargs = self.auto_refresh_kwargs.copy()

if 'auth' in kwargs:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should defend against auth being present but None.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, will update.

warnings.warn('client_id provided, but '
'client_secret missing')
client_secret = ''
refresh_kwargs['auth'] = \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A style note: we'd rather use implicit newlines inside parentheses than explicit ones.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newline does not show up in the resulting string, it is strictly for formatting, the two strings end up concatenated into one (single line) string.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example:

>>> print('this is a multi-'
... 'line string in the code but'
... ' a single line when printed.')
this is a multi-line string in the code but a single line when printed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know. I'm saying don't use \ (the explicit line continuation character), use parentheses instead.

auth = requests.auth.HTTPBasicAuth(client_id, client_secret)
if not client_secret:
warnings.warn('client_id provided, but '
'client_secret missing')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this warning? I'm not certain how likely this is to be an error.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it because the code replaces the missing argument with an empty string and continues with authentication. I thought that seemed like an omission on the callers part, something they might need warned about. This could be an incorrect assumption.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than do that, let's just require both the client ID and secret.

@btimby
Copy link
Author

btimby commented Mar 3, 2017

Even after I make the requested changes, I am still testing, so please don't merge this. I will likely add new unit tests.

@coveralls
Copy link

coveralls commented Mar 3, 2017

Coverage Status

Coverage decreased (-0.1%) to 86.875% when pulling 6960d8d on btimby:master into a618145 on requests:master.

@benh57
Copy link

benh57 commented Mar 17, 2017

This change worked perfectly for me.

# compatibility

# Start with kwargs explicitly requested for refresh.
refresh_kwargs = self.auto_refresh_kwargs.copy()
Copy link

@east825 east825 May 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder, isn't it going to change the semantic of auto_refresh_kwargs parameter? Previously it was intended to contain only key-value pairs to include into the body of the request, but now it also holds arguments of refresh_token() method such as auth, timeout, proxies, etc. For instance, if somebody wants to send auth parameter in the request body together with refresh_token and grant_type, this change will break their code.

@singingwolfboy
Copy link
Member

Even after I make the requested changes, I am still testing, so please don't merge this. I will likely add new unit tests.

@btimby, are you still working on this? If you're still interested in getting this change merged, you should probably rebase it on the latest master, and then we can try again to get it reviewed and merged.

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.

6 participants