-
Notifications
You must be signed in to change notification settings - Fork 14.2k
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
[AIRFLOW-3705] Fix PostgresHook get_conn to use conn_name_attr #5841
[AIRFLOW-3705] Fix PostgresHook get_conn to use conn_name_attr #5841
Conversation
Build failure says this at the very bottom:
Does this seem likely caused by these code changes, or is this a known/transient issue? |
5ba1722
to
d8beac9
Compare
Looks like the first build failure must have been a transient error. Anything else needed for this one to get merged? |
Can you explain exactly why this is needed? Is there a reason you can't set postgres_conn_id inside subclass's constructor? Something like: class UnitTestPostgresHook(PostgresHook):
def __int__(self, test_conn_id, **kwargs)
super().__init__(postgres_conn_id=test_conn_id, **kwargs) That way no change is needed to airflow. |
@ashb - I see your point. This looked like a bug to us when we sub-classed the Hook to connect to a Redshift instance. We set I'm working on your suggestion in my own code and have not yet gotten my own tests to pass, but I can keep trying. I think I'm seeing now that this attribute really isn't meant to be changed and is really more for the entire hook class, correct? |
Oh, I hadn't noticed that conn_name_attr is part of the "api" defined from the DbApiHook (I haven't used any of the DB hooks in Airflow), in which case although my change would probably work, the this PR probably makes sense. |
d8beac9
to
a7918be
Compare
Update PostgresHook's get_conn method to directly call the specified conn_name_attr rather that always using self.postgres_conn_id. Currently subclassing PostgresHook requires overriding the postgres_conn_id attribute in order to establish a separate connection. Add an additional unit test for this case checking that the subclassed PostgresHook's get_conn calls the correct arguments and that the hook calls the correction connection_id in get_connection.
a7918be
to
d75880c
Compare
@ashb - all right, I incorporated those changes you suggested and got a green build. Any other thoughts or suggestions? Thanks for the suggestion! I do like how much more explicit this test is than what I had before 👍 |
…e#5841) Update PostgresHook's get_conn method to directly call the specified conn_name_attr rather that always using self.postgres_conn_id. Currently subclassing PostgresHook requires overriding the postgres_conn_id attribute in order to establish a separate connection. Add an additional unit test for this case checking that the subclassed PostgresHook's get_conn calls the correct arguments and that the hook calls the correction connection_id in get_connection.
Update PostgresHook's get_conn method to directly call the specified conn_name_attr rather that always using self.postgres_conn_id. Currently subclassing PostgresHook requires overriding the postgres_conn_id attribute in order to establish a separate connection. Add an additional unit test for this case checking that the subclassed PostgresHook's get_conn calls the correct arguments and that the hook calls the correction connection_id in get_connection. (cherry picked from commit f823a66)
…e#5841) Update PostgresHook's get_conn method to directly call the specified conn_name_attr rather that always using self.postgres_conn_id. Currently subclassing PostgresHook requires overriding the postgres_conn_id attribute in order to establish a separate connection. Add an additional unit test for this case checking that the subclassed PostgresHook's get_conn calls the correct arguments and that the hook calls the correction connection_id in get_connection. (cherry picked from commit f823a66)
Make sure you have checked all steps below.
Jira
Description
Update the
get_conn
method ofPostgresHook
to ensure that theconn_name_attr
specified is used to establish the connection viapsycopg2
.This is an issue when subclassing
PostgresHook
. Thepostgres_conn_id
attribute must be overridden since it is explicitly used in establishing the connection. Now any givenconn_name_attr
set when subclassing will be used when connecting.Tests
PostgresHook
with a newconn_name_attr
which is used inTestPostgresHookConn
. This illustrates the problem with the default behavior forget_conn
with three test failures that say:Commits
Code Quality
flake8