-
Notifications
You must be signed in to change notification settings - Fork 834
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
Fix regression in v2.3.0 #544
Conversation
Codecov Report
@@ Coverage Diff @@
## master #544 +/- ##
==========================================
- Coverage 68.87% 68.85% -0.03%
==========================================
Files 15 15
Lines 1722 1724 +2
Branches 97 98 +1
==========================================
+ Hits 1186 1187 +1
Misses 511 511
- Partials 25 26 +1
Continue to review full report at Codecov.
|
slack/web/base_client.py
Outdated
@@ -265,7 +265,8 @@ def _get_url(self, api_method): | |||
) | |||
response = {"data": data, "headers": res.headers, "status_code": res.status} | |||
|
|||
await session.close() | |||
if not self.session or self.session.closed: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, does the code you intended seem to be 2) in the following examples?
class Session:
def closed(self):
true
null_session = None
closed_session = Session()
# 1)
if not null_session or closed_session.closed:
print("x")
# 2)
if not (null_session or closed_session.closed):
print("y")
Result:
>>> class Session:
... def closed(self):
... true
...
>>> null_session = None
>>> closed_session = Session()
>>>
>>>
>>> if not null_session or closed_session.closed:
... print("x")
...
x
>>>
>>> if not (null_session or closed_session.closed):
... print("y")
...
>>>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it's not, it's rather if not (null_session and not closed_session.closed):
which is the negation of the condition at this line https://github.com/slackapi/python-slackclient/blob/master/slack/web/base_client.py#L249.
The idea is to close the session created here: https://github.com/slackapi/python-slackclient/blob/master/slack/web/base_client.py#L252.
I updated the PR accordingly to avoid this confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the further explanation. I understand the point.
To me, double negative logic looks a bit confusing. Defining a local value may be easier-to-understand (and is good for maintainability, too).
use_running_session = self.session and not self.session.closed
if use_running_session:
session = self.session
else:
session = aiohttp.ClientSession(
timeout=aiohttp.ClientTimeout(total=self.timeout),
auth=req_args.pop("auth", None),
)
(omitted)
if not use_running_session:
await session.close()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, this approach looks better.
Thanks for your input, I've updated the commit.
fa7bd6b
to
3e1b36a
Compare
We must only close the temporary session used for the request. Fixes: 854920d Signed-off-by: Fatih Acar <f.acar@criteo.com>
3e1b36a
to
4f167d0
Compare
@fatih-acar Thanks for the contribution! A new version will be shipped very soon. |
Thanks for fixing this. Do you have any idea when it will be released? |
I'll be releasing a patch today.
|
Thanks for fixing this. |
Make sure we do not close the running session
We must only close the temporary session used for the request.
Fixes: 854920d
Signed-off-by: Fatih Acar f.acar@criteo.com
Summary
Latest release (v2.3.0) introduced a regression which make our slack app crash.
The associated traceback looks like:
Requirements (place an
x
in each[ ]
)