You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/03/28 14:15:42 UTC
[GitHub] [airflow] zeroam opened a new pull request #7953: close sftp
connection without error
zeroam opened a new pull request #7953: close sftp connection without error
URL: https://github.com/apache/airflow/pull/7953
check self.conn is None and close connection without error like
SSHHook
https://github.com/apache/airflow/blob/7b288a2f7ae48e266935e61ff743378232226bc0/airflow/providers/ssh/hooks/ssh.py#L209-L212
---
Issue link: WILL BE INSERTED BY [boring-cyborg](https://github.com/kaxil/boring-cyborg)
Make sure to mark the boxes below before creating PR: [x]
- [ ] Description above provides context of the change
- [ ] Unit tests coverage for changes (not needed for documentation changes)
- [ ] Commits follow "[How to write a good git commit message](http://chris.beams.io/posts/git-commit/)"
- [ ] Relevant documentation is updated including usage instructions.
- [ ] I will engage committers as explained in [Contribution Workflow Example](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#contribution-workflow-example).
---
In case of fundamental code change, Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+Proposals)) is needed.
In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
In case of backwards incompatible changes please leave a note in [UPDATING.md](https://github.com/apache/airflow/blob/master/UPDATING.md).
Read the [Pull Request Guidelines](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#pull-request-guidelines) for more information.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [airflow] zeroam commented on a change in pull request #7953: close
sftp connection without error
Posted by GitBox <gi...@apache.org>.
zeroam commented on a change in pull request #7953: close sftp connection without error
URL: https://github.com/apache/airflow/pull/7953#discussion_r399871650
##########
File path: airflow/providers/sftp/hooks/sftp.py
##########
@@ -120,12 +120,11 @@ def get_conn(self) -> pysftp.Connection:
def close_conn(self) -> None:
"""
- Closes the connection. An error will occur if the
- connection wasnt ever opened.
+ Closes the connection
"""
- conn = self.conn
- conn.close() # type: ignore
- self.conn = None
+ if self.conn is not None:
+ self.conn.close()
+ self.conn = None
Review comment:
I think when we initialize SFTPHook, self.conn is None.
This may cause an error in two case
1. call `close_conn` without a connection
2. call `close_conn` more than once after connection
it's not necessary to cause an error in this case
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [airflow] potiuk merged pull request #7953: close sftp connection
without error
Posted by GitBox <gi...@apache.org>.
potiuk merged pull request #7953: close sftp connection without error
URL: https://github.com/apache/airflow/pull/7953
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [airflow] zhongjiajie commented on a change in pull request #7953:
close sftp connection without error
Posted by GitBox <gi...@apache.org>.
zhongjiajie commented on a change in pull request #7953: close sftp connection without error
URL: https://github.com/apache/airflow/pull/7953#discussion_r399674024
##########
File path: airflow/providers/sftp/hooks/sftp.py
##########
@@ -120,12 +120,11 @@ def get_conn(self) -> pysftp.Connection:
def close_conn(self) -> None:
"""
- Closes the connection. An error will occur if the
- connection wasnt ever opened.
+ Closes the connection
"""
- conn = self.conn
- conn.close() # type: ignore
- self.conn = None
+ if self.conn is not None:
Review comment:
```suggestion
if not self.conn:
```
Maybe better
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [airflow] potiuk commented on a change in pull request #7953: close
sftp connection without error
Posted by GitBox <gi...@apache.org>.
potiuk commented on a change in pull request #7953: close sftp connection without error
URL: https://github.com/apache/airflow/pull/7953#discussion_r399957983
##########
File path: airflow/providers/sftp/hooks/sftp.py
##########
@@ -120,12 +120,11 @@ def get_conn(self) -> pysftp.Connection:
def close_conn(self) -> None:
"""
- Closes the connection. An error will occur if the
- connection wasnt ever opened.
+ Closes the connection
"""
- conn = self.conn
- conn.close() # type: ignore
- self.conn = None
+ if self.conn is not None:
+ self.conn.close()
+ self.conn = None
Review comment:
Yeah. Setting it to none is good.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [airflow] codecov-io commented on issue #7953: close sftp
connection without error
Posted by GitBox <gi...@apache.org>.
codecov-io commented on issue #7953: close sftp connection without error
URL: https://github.com/apache/airflow/pull/7953#issuecomment-605788233
# [Codecov](https://codecov.io/gh/apache/airflow/pull/7953?src=pr&el=h1) Report
> Merging [#7953](https://codecov.io/gh/apache/airflow/pull/7953?src=pr&el=desc) into [master](https://codecov.io/gh/apache/airflow/commit/996bf2efc73e9aa02b19139c7f593c5107c982d2&el=desc) will **decrease** coverage by `0.75%`.
> The diff coverage is `100.00%`.
[![Impacted file tree graph](https://codecov.io/gh/apache/airflow/pull/7953/graphs/tree.svg?width=650&height=150&src=pr&token=WdLKlKHOAU)](https://codecov.io/gh/apache/airflow/pull/7953?src=pr&el=tree)
```diff
@@ Coverage Diff @@
## master #7953 +/- ##
==========================================
- Coverage 87.16% 86.41% -0.76%
==========================================
Files 932 932
Lines 45187 45187
==========================================
- Hits 39389 39049 -340
- Misses 5798 6138 +340
```
| [Impacted Files](https://codecov.io/gh/apache/airflow/pull/7953?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [airflow/providers/sftp/hooks/sftp.py](https://codecov.io/gh/apache/airflow/pull/7953/diff?src=pr&el=tree#diff-YWlyZmxvdy9wcm92aWRlcnMvc2Z0cC9ob29rcy9zZnRwLnB5) | `94.84% <100.00%> (ø)` | |
| [...flow/providers/apache/cassandra/hooks/cassandra.py](https://codecov.io/gh/apache/airflow/pull/7953/diff?src=pr&el=tree#diff-YWlyZmxvdy9wcm92aWRlcnMvYXBhY2hlL2Nhc3NhbmRyYS9ob29rcy9jYXNzYW5kcmEucHk=) | `21.25% <0.00%> (-72.50%)` | :arrow_down: |
| [...w/providers/apache/hive/operators/mysql\_to\_hive.py](https://codecov.io/gh/apache/airflow/pull/7953/diff?src=pr&el=tree#diff-YWlyZmxvdy9wcm92aWRlcnMvYXBhY2hlL2hpdmUvb3BlcmF0b3JzL215c3FsX3RvX2hpdmUucHk=) | `35.84% <0.00%> (-64.16%)` | :arrow_down: |
| [airflow/kubernetes/volume\_mount.py](https://codecov.io/gh/apache/airflow/pull/7953/diff?src=pr&el=tree#diff-YWlyZmxvdy9rdWJlcm5ldGVzL3ZvbHVtZV9tb3VudC5weQ==) | `44.44% <0.00%> (-55.56%)` | :arrow_down: |
| [airflow/providers/postgres/operators/postgres.py](https://codecov.io/gh/apache/airflow/pull/7953/diff?src=pr&el=tree#diff-YWlyZmxvdy9wcm92aWRlcnMvcG9zdGdyZXMvb3BlcmF0b3JzL3Bvc3RncmVzLnB5) | `47.82% <0.00%> (-52.18%)` | :arrow_down: |
| [airflow/providers/redis/operators/redis\_publish.py](https://codecov.io/gh/apache/airflow/pull/7953/diff?src=pr&el=tree#diff-YWlyZmxvdy9wcm92aWRlcnMvcmVkaXMvb3BlcmF0b3JzL3JlZGlzX3B1Ymxpc2gucHk=) | `50.00% <0.00%> (-50.00%)` | :arrow_down: |
| [airflow/kubernetes/volume.py](https://codecov.io/gh/apache/airflow/pull/7953/diff?src=pr&el=tree#diff-YWlyZmxvdy9rdWJlcm5ldGVzL3ZvbHVtZS5weQ==) | `52.94% <0.00%> (-47.06%)` | :arrow_down: |
| [airflow/providers/mongo/sensors/mongo.py](https://codecov.io/gh/apache/airflow/pull/7953/diff?src=pr&el=tree#diff-YWlyZmxvdy9wcm92aWRlcnMvbW9uZ28vc2Vuc29ycy9tb25nby5weQ==) | `53.33% <0.00%> (-46.67%)` | :arrow_down: |
| [airflow/kubernetes/pod\_launcher.py](https://codecov.io/gh/apache/airflow/pull/7953/diff?src=pr&el=tree#diff-YWlyZmxvdy9rdWJlcm5ldGVzL3BvZF9sYXVuY2hlci5weQ==) | `47.18% <0.00%> (-45.08%)` | :arrow_down: |
| [airflow/providers/mysql/operators/mysql.py](https://codecov.io/gh/apache/airflow/pull/7953/diff?src=pr&el=tree#diff-YWlyZmxvdy9wcm92aWRlcnMvbXlzcWwvb3BlcmF0b3JzL215c3FsLnB5) | `55.00% <0.00%> (-45.00%)` | :arrow_down: |
| ... and [9 more](https://codecov.io/gh/apache/airflow/pull/7953/diff?src=pr&el=tree-more) | |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/airflow/pull/7953?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/airflow/pull/7953?src=pr&el=footer). Last update [996bf2e...d078d0a](https://codecov.io/gh/apache/airflow/pull/7953?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [airflow] zeroam commented on a change in pull request #7953: close
sftp connection without error
Posted by GitBox <gi...@apache.org>.
zeroam commented on a change in pull request #7953: close sftp connection without error
URL: https://github.com/apache/airflow/pull/7953#discussion_r399870753
##########
File path: airflow/providers/sftp/hooks/sftp.py
##########
@@ -120,12 +120,11 @@ def get_conn(self) -> pysftp.Connection:
def close_conn(self) -> None:
"""
- Closes the connection. An error will occur if the
- connection wasnt ever opened.
+ Closes the connection
"""
- conn = self.conn
- conn.close() # type: ignore
- self.conn = None
+ if self.conn is not None:
Review comment:
Good suggestion. I think `is not None` is more clear and cause less error.
like this
```python
>>> x = 0
>>> x is not None
True
>>> not x
True
>>> y = 1
>>> y is not None
True
>>> not y
False
>>> z = None
>>> z is not None
False
>>> not z
True
```
check this: https://stackoverflow.com/questions/2710940/python-if-x-is-not-none-or-if-not-x-is-none
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [airflow] potiuk commented on a change in pull request #7953: close
sftp connection without error
Posted by GitBox <gi...@apache.org>.
potiuk commented on a change in pull request #7953: close sftp connection without error
URL: https://github.com/apache/airflow/pull/7953#discussion_r399958364
##########
File path: airflow/providers/sftp/hooks/sftp.py
##########
@@ -120,12 +120,11 @@ def get_conn(self) -> pysftp.Connection:
def close_conn(self) -> None:
"""
- Closes the connection. An error will occur if the
- connection wasnt ever opened.
+ Closes the connection
"""
- conn = self.conn
- conn.close() # type: ignore
- self.conn = None
+ if self.conn is not None:
Review comment:
I like "is not None" a bit better in this case. it's a little longer, but I think we should optimise for readability and "is not None" reads better in this case.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [airflow] zhongjiajie commented on a change in pull request #7953:
close sftp connection without error
Posted by GitBox <gi...@apache.org>.
zhongjiajie commented on a change in pull request #7953: close sftp connection without error
URL: https://github.com/apache/airflow/pull/7953#discussion_r399674714
##########
File path: airflow/providers/sftp/hooks/sftp.py
##########
@@ -120,12 +120,11 @@ def get_conn(self) -> pysftp.Connection:
def close_conn(self) -> None:
"""
- Closes the connection. An error will occur if the
- connection wasnt ever opened.
+ Closes the connection
"""
- conn = self.conn
- conn.close() # type: ignore
- self.conn = None
+ if self.conn is not None:
+ self.conn.close()
+ self.conn = None
Review comment:
And I wander, could we just do
```py
if not self.conn:
self.conn.close()
```
If we already check if conn is null or not?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services