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

Replace http_request_full internals with treq #1058

Merged

Conversation

smn
Copy link
Member

@smn smn commented Oct 25, 2016

No description provided.

@KaitCrawford
Copy link
Contributor

@smn I just changed the order of things a little

@smn
Copy link
Member Author

smn commented Apr 20, 2017

💥 amazing! Thank you :) 🍰 🍰 🍰 👍

@erikh360
Copy link
Contributor

erikh360 commented May 4, 2017

👍

Copy link
Contributor

@JayH5 JayH5 left a comment

Choose a reason for hiding this comment

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

Did you look into the context factory stuff in the sandbox? Not sure if this is the only place this needs to be fixed...

vumi/utils.py Outdated
from twisted.web.server import Site
from twisted.web.http_headers import Headers
from twisted.web.iweb import IBodyProducer
from twisted.web.http import PotentialDataLoss
from twisted.web.resource import Resource
from treq._utils import default_pool, default_reactor
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it's a good idea to import from a private module.. These methods could change.

Copy link
Contributor

Choose a reason for hiding this comment

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

And you don't seem to be using default_reactor.

Copy link
Contributor

Choose a reason for hiding this comment

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

when calling default_pool we were sending pool=None and persistence=False. In that case the method will create a new HTTPSConnectionPool. so that is what I did instead.
https://github.com/twisted/treq/blob/master/src/treq/_utils.py#L38-L42

d.addCallback(handle_response)

if timeout is not None:
cancelling_on_timeout = [False]
Copy link
Contributor

Choose a reason for hiding this comment

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

Reason that this is a list?

Copy link
Contributor

Choose a reason for hiding this comment

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

@smn perhaps you can answer this?

Copy link
Member Author

Choose a reason for hiding this comment

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

the why escapes me, this was many years ago, I got it from the old implementation: https://github.com/praekelt/vumi/pull/1058/files/a22e08f7250ab6570fd96b8469d96090696b4560#diff-832ae36feb20f811191dde6be9132638R195

perhaps @jerith remembers?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this not something to do with that False in python is a simple variable, where as [False] is an object?

>>> False is False
True
>>> [False] is [False]
False```

Copy link
Member

Choose a reason for hiding this comment

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

It's a hack to get a mutable value that can be modified elsewhere:

>>> foo = [1]; print foo, id(foo)
[1] 4359988792
>>> foo[0] = 2; print foo, id(foo)
[2] 4359988792

This lets us pass cancelling_on_timeout through a bunch of other code (which can modify the contents) and then check it later to see if it's been changed. Note that this pattern also requires modifications to be of the form foo[0] = 3 (update the existing list) rather than foo = [3] (replace the list with a new one).

Copy link
Member

Choose a reason for hiding this comment

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

In this particular case, we use cancelling_on_timeout to get information from cancel_on_timeout() (which is scheduled to cancel the request after some time) into the raise_timeout() errback so we can raise a timeout exception instead of a generic cancellation exception or whatever.

@KaitCrawford
Copy link
Contributor

@JayH5 ^^ this commit removes usage of WebClientContextFactory() from the sandbox and it doesn't appear anywhere else in the repo. I'm not sure if that's enough though?

@JayH5
Copy link
Contributor

JayH5 commented May 5, 2017

@KaitCrawford I actually read the sandbox.py file.. it says it's deprecated and people should use vxsandbox rather which is what we do for Seed. So I'd say maybe actually just don't touch sandbox.py in this PR.

@JayH5
Copy link
Contributor

JayH5 commented May 5, 2017

Looks like this is definitely fixed in vxsandbox, even if treq isn't used there: https://github.com/praekelt/vumi-sandbox/blob/develop/vxsandbox/resources/http.py#L23-L41

Copy link
Contributor

@JayH5 JayH5 left a comment

Choose a reason for hiding this comment

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

👍 🍰 🍥

@KaitCrawford KaitCrawford merged commit 61278c4 into develop May 9, 2017
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.

None yet

6 participants