mingrammer commented on a change in pull request #6432: [AIRFLOW-5758] Support
the custom cursor classes for the PostgreSQL hook
URL: https://github.com/apache/airflow/pull/6432#discussion_r339304130
##########
File path: airflow/hooks/postgres_hook.py
##########
@@ -67,6 +68,13 @@ def get_conn(self):
password=conn.password,
dbname=self.schema or conn.schema,
port=conn.port)
+ if conn.extra_dejson.get('cursor', False):
+ if (conn.extra_dejson['cursor']).lower() == 'dictcursor':
+ conn_args['cursor_factory'] = psycopg2.extras.DictCursor
+ elif (conn.extra_dejson['cursor']).lower() == 'realdictcursor':
+ conn_args['cursor_factory'] = psycopg2.extras.RealDictCursor
+ elif (conn.extra_dejson['cursor']).lower() == 'namedtuplecursor':
+ conn_args['cursor_factory'] = psycopg2.extras.NamedTupleCursor
Review comment:
Hm, wait. `conn` is a local variable for `get_conn` method. So we should get
the connection in the `_get_cursor` again by
```python
conn_id = getattr(self, self.conn_name_attr)
conn = self.get_connection(conn_id)
```
So `get_connection` will be called twice when cursor class is specified. Is
it ok?
Or we can pass the `conn.extra_dejson['cursor']` to the `_get_cursor` from
`get_conn`.
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services