josh-fell commented on a change in pull request #20189:
URL: https://github.com/apache/airflow/pull/20189#discussion_r766334248
##########
File path: airflow/providers/neo4j/operators/neo4j.py
##########
@@ -50,13 +50,11 @@ def __init__(
self.neo4j_conn_id = neo4j_conn_id
self.sql = sql
self.parameters = parameters
- self.hook = None
def get_hook(self):
"""Function to retrieve the Neo4j Hook."""
return Neo4jHook(conn_id=self.neo4j_conn_id)
def execute(self, context: Dict) -> None:
self.log.info('Executing: %s', self.sql)
- self.hook = self.get_hook()
- self.hook.run(self.sql)
+ self.get_hook().run(self.sql)
Review comment:
This could probably be simplified. The `get_hook()` method could be
removed and the SQL execution logic turns into something like:
```python
hook = Neo4jHook(conn_id=self.neo4j_conn_id)
hook.run(self.sql)
```
Doesn't seem like `hook` needs to be an instance attribute.
##########
File path: airflow/providers/influxdb/hooks/influxdb.py
##########
@@ -50,7 +50,7 @@ def __init__(self, conn_id: str = default_conn_name, *args,
**kwargs) -> None:
self.influxdb_conn_id = conn_id
self.connection = kwargs.pop("connection", None)
self.client = None
- self.extras = None
+ self.extras: Dict = {}
Review comment:
Does `extras` need to be an instance attribute of the hook? Looks like
`self.extras` is only accessed and used in the `get_conn()` method. Could get
rid of the typing issues that way.
Might be the same behavior for some of the other hook attributes as well
that are initialized to `None`.
##########
File path: airflow/providers/neo4j/hooks/neo4j.py
##########
@@ -44,8 +45,8 @@ def __init__(self, conn_id: str = default_conn_name, *args,
**kwargs) -> None:
self.neo4j_conn_id = conn_id
self.connection = kwargs.pop("connection", None)
self.client = None
- self.extras = None
- self.uri = None
+ self.extras: Dict = {}
+ self.uri: str = ""
Review comment:
Same comment here if these really need to be hook instance attributes.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]