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

Clone web request's state #2287

Merged
merged 1 commit into from
Sep 23, 2017
Merged

Clone web request's state #2287

merged 1 commit into from
Sep 23, 2017

Conversation

asvetlov
Copy link
Member

Fix for #2284

@asvetlov asvetlov added the bug label Sep 23, 2017
@asvetlov asvetlov added this to the 2.3 milestone Sep 23, 2017
@@ -120,7 +123,8 @@ def clone(self, *, method=sentinel, rel_url=sentinel,
self._time_service,
self._task,
self._loop,
secure_proxy_ssl_header=self._secure_proxy_ssl_header)
secure_proxy_ssl_header=self._secure_proxy_ssl_header,
state=self._state.copy())
Copy link
Member

Choose a reason for hiding this comment

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

I hope there are no nested dicts/list in state, right?

@codecov-io
Copy link

codecov-io commented Sep 23, 2017

Codecov Report

Merging #2287 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2287      +/-   ##
==========================================
+ Coverage   97.24%   97.24%   +<.01%     
==========================================
  Files          39       39              
  Lines        8094     8096       +2     
  Branches     1410     1411       +1     
==========================================
+ Hits         7871     7873       +2     
  Misses         97       97              
  Partials      126      126
Impacted Files Coverage Δ
aiohttp/web_request.py 99.68% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 98bc1e2...4dd1621. Read the comment docs.

@asvetlov
Copy link
Member Author

It's impossible to perform deep state copy for an obvious reasons: values are not copyable very often, they could be an opened socket for example.

Thus we have 3 options:

  1. Cleanup a state on copy.
  2. Do swallow copy.
  3. Share state between all copies.

I believe the option 2 is better than others.

@kxepal
Copy link
Member

kxepal commented Sep 23, 2017

@asvetlov What's a case for req.clone()? May be we can make it immutable instead to do not any copies?

@asvetlov
Copy link
Member Author

.clone() is intended to be used in middlewares:

@asyncio.coroutine
def middleware_factory(app, next_handler):
    @asyncio.coroutine
    def middleware(request):
        request2 = request.clone(rel_url="/new_url", method="GET")
        response = yield from next_handler(request2)
    return middleware

I'd like to extend clone() params for fixing #2171 too.

@kxepal
Copy link
Member

kxepal commented Sep 23, 2017

Hm...I see. Then it seems swallow copy is the only option.

@asvetlov asvetlov merged commit f3db000 into master Sep 23, 2017
@asvetlov asvetlov deleted the fix-req-state branch September 23, 2017 17:58
@lock
Copy link

lock bot commented Oct 28, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs.
If you feel like there's important points made in this discussion, please include those exceprts into that [new issue].
[new issue]: https://github.com/aio-libs/aiohttp/issues/new

@lock lock bot added the outdated label Oct 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bot:chronographer:provided There is a change note present in this PR bug outdated
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants