Skip to content

Conversation

@zhongjiajie
Copy link
Member


Issue link: WILL BE INSERTED BY boring-cyborg

Make sure to mark the boxes below before creating PR: [x]


In case of fundamental code change, Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in UPDATING.md.
Read the Pull Request Guidelines for more information.

@zhongjiajie zhongjiajie changed the title Add property conn_name to dbapi_hook [dont-merge] Add property conn_name to dbapi_hook Mar 27, 2020
@zhongjiajie
Copy link
Member Author

We have one subclass hook still WIP in #7901

@zhongjiajie zhongjiajie force-pushed the hook_db_avoid_pylint_no_member branch from ebfdfb0 to e5aa2a4 Compare March 31, 2020 02:19
@zhongjiajie zhongjiajie changed the title [dont-merge] Add property conn_name to dbapi_hook Add conn_name and get_connection to dbapi_hook Mar 31, 2020
@zhongjiajie
Copy link
Member Author

zhongjiajie commented Mar 31, 2020

For reviewer, in cf0a5f6 I just add property conn_name to get conn_name.

And then I find out we could change conn = self.get_connection(self.conn_name) to conn = self.get_connection() due to self.conn_name almost same in subclass of DBAPI and is no need, So I add function get_connection in dbapi_hook to get conn_name if no conn_id pass from subclass. In the last change in e5aa2a4

Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good. I would like to understand though why it was done like that in the first place. seems unnecessary complex - maybe others (@feluelle @mik-laj can take a look and shed some light on it ) :)

@feluelle
Copy link
Member

It looks good. I would like to understand though why it was done like that in the first place. seems unnecessary complex - maybe others (@feluelle @mik-laj can take a look and shed some light on it ) :)

I agree with you Jarek. I also don't know why it is as it is. 🤔

@zhongjiajie
Copy link
Member Author

My laptop almost power off and I forget the charger in office, have to continue in tomorrow.

@zhongjiajie zhongjiajie force-pushed the hook_db_avoid_pylint_no_member branch 3 times, most recently from 1b07b54 to 81acdae Compare April 7, 2020 07:07
@zhongjiajie zhongjiajie force-pushed the hook_db_avoid_pylint_no_member branch 2 times, most recently from b33346b to 124c19d Compare April 7, 2020 14:25
@codecov-io
Copy link

Codecov Report

Merging #7903 into master will decrease coverage by 55.04%.
The diff coverage is 11.42%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master    #7903       +/-   ##
===========================================
- Coverage   88.31%   33.26%   -55.05%     
===========================================
  Files         935      935               
  Lines       45170    45170               
===========================================
- Hits        39892    15027    -24865     
- Misses       5278    30143    +24865     
Impacted Files Coverage Δ
airflow/providers/apache/druid/hooks/druid.py 24.35% <0.00%> (-65.39%) ⬇️
airflow/providers/apache/hive/hooks/hive.py 13.88% <0.00%> (-63.64%) ⬇️
airflow/providers/apache/pinot/hooks/pinot.py 19.23% <0.00%> (-72.31%) ⬇️
...low/providers/elasticsearch/hooks/elasticsearch.py 21.62% <0.00%> (-24.54%) ⬇️
airflow/providers/jdbc/hooks/jdbc.py 47.36% <0.00%> (-52.64%) ⬇️
airflow/providers/microsoft/mssql/hooks/mssql.py 61.90% <0.00%> (-14.29%) ⬇️
...rflow/providers/microsoft/mssql/operators/mssql.py 42.42% <0.00%> (-48.21%) ⬇️
airflow/providers/mysql/hooks/mysql.py 19.79% <0.00%> (-72.92%) ⬇️
airflow/providers/odbc/hooks/odbc.py 25.55% <0.00%> (-66.67%) ⬇️
airflow/providers/oracle/hooks/oracle.py 9.40% <0.00%> (-86.33%) ⬇️
... and 822 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0dafdd0...124c19d. Read the comment docs.

@zhongjiajie
Copy link
Member Author

And for now, the solution two pass CI, and I think it work.

The question is, should we take solution one and change get_connection in dbapi_hook to property connection? If we use solution one, subclass of dbapi_hook have to use self.connection to get connection which is different from subclass from base_hook(using get_connection)

But if we take solution two, get_connection don't pass mypy check, and self.get_connection and DbApiHook.get_connection call different method, I think it will confuse user when calling it

@zhongjiajie zhongjiajie force-pushed the hook_db_avoid_pylint_no_member branch from 124c19d to c7e90c7 Compare April 8, 2020 12:13
@zhongjiajie zhongjiajie force-pushed the hook_db_avoid_pylint_no_member branch 2 times, most recently from 591bea2 to 31fd691 Compare April 19, 2020 17:34
@zhongjiajie zhongjiajie changed the title Add conn_name and get_connection to dbapi_hook Add property conn_name and connection to dbapi_hook Apr 19, 2020
@zhongjiajie zhongjiajie force-pushed the hook_db_avoid_pylint_no_member branch 2 times, most recently from 75ef759 to 9b60c0e Compare April 20, 2020 13:18
@zhongjiajie
Copy link
Member Author

Two solutions CI passed, we have two fix solutions here, I prefer the second one, and it also the PR final status

  • Add # type: ignore in L76 in dbapi_hook to avoid error: Signature of "get_connection" incompatible with supertype "BaseHook"
-    def get_connection(self, conn_id: Optional[str] = None) -> Connection:
+    def get_connection(self, conn_id: Optional[str] = None) -> Connection:  # type: ignore
  • Using property function connection in dbapi_hook to get connection, which complete fix Signature error, and make dbapi_hook more easier.

@zhongjiajie zhongjiajie requested review from feluelle and potiuk April 20, 2020 14:36
@kaxil kaxil added this to the Airflow 1.10.12 milestone Jun 22, 2020
@zhongjiajie
Copy link
Member Author

Reopen this stale PR

@zhongjiajie zhongjiajie reopened this Jul 6, 2020
@stale stale bot removed the stale Stale PRs per the .github/workflows/stale.yml policy file label Jul 6, 2020
@zhongjiajie
Copy link
Member Author

@feluelle @potiuk @kaxil @kaxil @turbaszek I think I need one approving review here. I checked and find out there no DbApiHook subclass add during this time, which mean this patch cover/change all DbApiHook subclass.

@zhongjiajie
Copy link
Member Author

zhongjiajie commented Jul 7, 2020

Ok, we have +1 here, if no one disapproval here in a few day I will merge this patch to master.

@feluelle
Copy link
Member

feluelle commented Jul 7, 2020

Please rebase once again - just to be sure. :)

It is very long ago since you last pushed a commit.

@zhongjiajie zhongjiajie force-pushed the hook_db_avoid_pylint_no_member branch from 1748118 to 5330d27 Compare July 10, 2020 13:05
@zhongjiajie
Copy link
Member Author

Thanks @turbaszek @feluelle, now I rebase and push to restart the CI, will merge when it pass

Copy link
Member

@feluelle feluelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I am a bit confused by all these connection, _connection, ... parameters.

Wouldn't it be easier if we just use the conn_id like we do in other hooks which are not based on dbapi_hook ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def connection_(self):
def connection(self):

You can overwrite it.

Comment on lines 130 to 131
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to change it to pass CI, I have no idea why previous code could pass the CI, mypy will raise error cause aws_access_key_id, aws_secret_access_key maybe not define

Comment on lines 36 to 41
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the Connection class to init a connection like in the other cases.

For example:

self.conn = mock.Mock(return_value=Connection(...))

@feluelle
Copy link
Member

So my suggestion is to remove conn_name_attr and add a *_conn_id parameter to init. WDYT @turbaszek @zhongjiajie ?

As it is now I am not a fan of it anymore I am sorry @zhongjiajie but this looks really too complex, don't you think?

@zhongjiajie
Copy link
Member Author

I think we should keep conn_name_attr but change property name which confused users, like connection as you said above. Cause we need dbapi_hook as parent class to handle some RDBMS like hook.

@zhongjiajie zhongjiajie changed the title Add property conn_name and connection to dbapi_hook [WIP] Add property conn_name and connection to dbapi_hook Jul 15, 2020
@kaxil kaxil modified the milestones: Airflow 1.10.12, Airflow 1.10.13 Aug 3, 2020
@stale
Copy link

stale bot commented Sep 20, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Stale PRs per the .github/workflows/stale.yml policy file label Sep 20, 2020
@stale stale bot closed this Oct 4, 2020
@kaxil kaxil removed this from the Airflow 1.10.13 milestone Nov 19, 2020
@zhongjiajie zhongjiajie reopened this Nov 24, 2020
@stale stale bot removed the stale Stale PRs per the .github/workflows/stale.yml policy file label Nov 24, 2020
* use conn_name to get dbapi_hook default_conn_name
* use get_connection get database connection with
  default conn_name
@zhongjiajie zhongjiajie force-pushed the hook_db_avoid_pylint_no_member branch from d9cf217 to 53f92d9 Compare November 27, 2020 05:15
@zhongjiajie zhongjiajie changed the title [WIP] Add property conn_name and connection to dbapi_hook Add property conn_name and connection to dbapi_hook Nov 27, 2020
@ashb
Copy link
Member

ashb commented Feb 8, 2021

@zhongjiajie Are you going to carry on with this PR? Where did we get to with it when we left off?

@github-actions
Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale Stale PRs per the .github/workflows/stale.yml policy file label Sep 16, 2021
@potiuk potiuk closed this Sep 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Stale PRs per the .github/workflows/stale.yml policy file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants