Skip to content
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

Fixed MyPy errors introduced by new mysql-connector-python #28995

Merged
merged 1 commit into from
Jan 18, 2023

Conversation

potiuk
Copy link
Member

@potiuk potiuk commented Jan 17, 2023

The new (8.0.32) mysql-connector-python introduces more typing and failed our MySQL provider mypy tests (because we are handling also other mysql clients)

Adding some excludes and handling None better for description solves the problem


^ Add meaningful description above

Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an 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 a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

The new (8.0.32) mysql-connector-python introduces more typing and
failed our MySQL provider mypy tests (because we are handling
also other mysql clients)

Adding some excludes and handling None better for description
solves the problem
@potiuk potiuk force-pushed the fix-mypy-errors-mysql-client branch from ff1b877 to 4a4c25f Compare January 17, 2023 21:08
Comment on lines -151 to +152
conn.close()
conn.close() # type: ignore[misc]
Copy link
Member

@uranusjr uranusjr Jan 18, 2023

Choose a reason for hiding this comment

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

What error does this ignore? (Also other ignores below.)

Copy link
Member Author

@potiuk potiuk Jan 18, 2023

Choose a reason for hiding this comment

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

See https://github.com/apache/airflow/actions/runs/3943690729/jobs/6749107020 for example:

airflow/providers/mysql/hooks/mysql.py:81: error: "bool" not callable 
[operator]
                conn.autocommit(autocommit)
                ^
airflow/providers/mysql/hooks/mysql.py:96: error: Item
"MySQLConnectionAbstract" of "Union[Any, MySQLConnectionAbstract]" has no
attribute "get_autocommit"  [union-attr]
                return conn.get_autocommit()
                       ^
airflow/providers/mysql/hooks/mysql.py:202: error: Attribute function "close"
with type "Callable[[], Any]" does not accept self argument  [misc]
            conn.close()
            ^
airflow/providers/mysql/hooks/mysql.py:215: error: Attribute function "close"
with type "Callable[[], Any]" does not accept self argument  [misc]
            conn.close()
            ^
airflow/providers/mysql/hooks/mysql.py:286: error: Attribute function "close"
with type "Callable[[], Any]" does not accept self argument  [misc]
            conn.close()
            ^
airflow/providers/apache/hive/transfers/mysql_to_hive.py:[146](https://github.com/apache/airflow/actions/runs/3943690729/jobs/6749107020#step:6:147): error: Item
"None" of
"Union[Any, List[Tuple[str, int, None, None, None, None, Union[bool, int], int, int]], None]"
has no attribute "__iter__" (not iterable)  [union-attr]
                for field in cursor.description:
                             ^
airflow/providers/apache/hive/transfers/mysql_to_hive.py:151: error: Attribute
function "close" with type "Callable[[], Any]" does not accept self argument 
[misc]
                conn.close()
                ^
Found 7 errors in 2 files (checked 930 source files)

I thiink it is a wrong typing coming from bad interpretation of our MySQL union typing. I have not figured out how to do it "properly" - but if you have an idea how to fix it better - I am all ears.

Copy link
Member

Choose a reason for hiding this comment

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

I’ll look into it later, merging this first wouldn’t break anything.

Copy link
Member Author

Choose a reason for hiding this comment

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

:D I thought you will be ok with it :)

@uranusjr uranusjr merged commit aa97474 into apache:main Jan 18, 2023
@potiuk potiuk added this to the Airflow 2.5.2 milestone Feb 8, 2023
@pierrejeambrun pierrejeambrun removed this from the Airflow 2.5.2 milestone Mar 6, 2023
@potiuk potiuk deleted the fix-mypy-errors-mysql-client branch March 22, 2023 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants