coopergillan commented on a change in pull request #5841: [AIRFLOW-3705] Fix
PostgresHook get_conn to use conn_name_attr
URL: https://github.com/apache/airflow/pull/5841#discussion_r316368793
##########
File path: tests/hooks/test_postgres_hook.py
##########
@@ -39,7 +39,10 @@ def setUp(self):
schema='schema'
)
- self.db_hook = PostgresHook()
+ class UnitTestPostgresHook(PostgresHook):
+ conn_name_attr = 'test_conn_id'
Review comment:
Once I had tried a few things, I ended up with this test-driven development
path:
1. Make the change above in `tests/hooks/test_postgres_hook.py` - note that
the subclass was copied from further down in the file, but I didn't an elegant
way to reuse that code, since it was for a different test case
2. Run the entire test suite and get this error (also in the PR description):
```python
AttributeError: 'UnitTestPostgresHook' object has no attribute
'postgres_conn_id'
```
3. Make the change to `airflow/hooks/postgres_hook.py` to call the
`conn_name_attr` rather than directly calling `postgres_conn_id`
4. See the tests pass
I think I what you called out sounds right-on: there is a `conn_name_attr`
used for connecting to any database using the `DbApiHook`, which is partly why
we went ahead and change this attribute when we sub-classed `PostgresHook`.
Anything else you all would need to see to make this change?
Thanks for considering!
----------------------------------------------------------------
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