Skip to content

Commit

Permalink
Fixed MyPy errors introduced by new mysql-connector-python
Browse files Browse the repository at this point in the history
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
  • Loading branch information
potiuk committed Jan 17, 2023
1 parent c568874 commit 4a4c25f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
7 changes: 4 additions & 3 deletions airflow/providers/apache/hive/transfers/mysql_to_hive.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,13 @@ def execute(self, context: Context):
encoding="utf-8",
)
field_dict = OrderedDict()
for field in cursor.description:
field_dict[field[0]] = self.type_map(field[1])
if cursor.description is not None:
for field in cursor.description:
field_dict[field[0]] = self.type_map(field[1])
csv_writer.writerows(cursor)
f.flush()
cursor.close()
conn.close()
conn.close() # type: ignore[misc]
self.log.info("Loading file into Hive")
hive.load_file(
f.name,
Expand Down
10 changes: 5 additions & 5 deletions airflow/providers/mysql/hooks/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def set_autocommit(self, conn: MySQLConnectionTypes, autocommit: bool) -> None:
if hasattr(conn.__class__, "autocommit") and isinstance(conn.__class__.autocommit, property):
conn.autocommit = autocommit
else:
conn.autocommit(autocommit)
conn.autocommit(autocommit) # type: ignore[operator]

def get_autocommit(self, conn: MySQLConnectionTypes) -> bool:
"""
Expand All @@ -93,7 +93,7 @@ def get_autocommit(self, conn: MySQLConnectionTypes) -> bool:
if hasattr(conn.__class__, "autocommit") and isinstance(conn.__class__.autocommit, property):
return conn.autocommit
else:
return conn.get_autocommit()
return conn.get_autocommit() # type: ignore[union-attr]

def _get_conn_config_mysql_client(self, conn: Connection) -> dict:
conn_config = {
Expand Down Expand Up @@ -199,7 +199,7 @@ def bulk_load(self, table: str, tmp_file: str) -> None:
"""
)
conn.commit()
conn.close()
conn.close() # type: ignore[misc]

def bulk_dump(self, table: str, tmp_file: str) -> None:
"""Dump a database table into a tab-delimited file."""
Expand All @@ -212,7 +212,7 @@ def bulk_dump(self, table: str, tmp_file: str) -> None:
"""
)
conn.commit()
conn.close()
conn.close() # type: ignore[misc]

@staticmethod
def _serialize_cell(cell: object, conn: Connection | None = None) -> Any:
Expand Down Expand Up @@ -283,4 +283,4 @@ def bulk_load_custom(

cursor.close()
conn.commit()
conn.close()
conn.close() # type: ignore[misc]

0 comments on commit 4a4c25f

Please sign in to comment.