-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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
Add Python 3.11 support #27264
Add Python 3.11 support #27264
Changes from all commits
e30ef21
41bc51c
82e45be
68018b4
a3162d2
4178cda
37ecfe6
9473115
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -207,7 +207,7 @@ def wait_for_task_status(self, replication_task_arn: str, status: DmsTaskWaiterS | |
raise TypeError("Status must be an instance of DmsTaskWaiterStatus") | ||
|
||
dms_client = self.get_conn() | ||
waiter = dms_client.get_waiter(f"replication_task_{status}") | ||
waiter = dms_client.get_waiter(f"replication_task_{status.value}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an interesitng one - turns out that Python 3.11 changes default There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From https://docs.python.org/3/whatsnew/3.11.html
|
||
waiter.wait( | ||
Filters=[ | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
from __future__ import annotations | ||
|
||
from collections import OrderedDict | ||
from contextlib import closing | ||
from tempfile import NamedTemporaryFile | ||
from typing import TYPE_CHECKING, Sequence | ||
|
||
|
@@ -131,28 +132,25 @@ def type_map(cls, mysql_type: int) -> str: | |
def execute(self, context: Context): | ||
hive = HiveCliHook(hive_cli_conn_id=self.hive_cli_conn_id, auth=self.hive_auth) | ||
mysql = MySqlHook(mysql_conn_id=self.mysql_conn_id) | ||
|
||
self.log.info("Dumping MySQL query results to local file") | ||
conn = mysql.get_conn() | ||
cursor = conn.cursor() | ||
cursor.execute(self.sql) | ||
with NamedTemporaryFile("wb") as f: | ||
csv_writer = csv.writer( | ||
f, | ||
delimiter=self.delimiter, | ||
quoting=self.quoting, | ||
quotechar=self.quotechar, | ||
escapechar=self.escapechar, | ||
encoding="utf-8", | ||
) | ||
field_dict = OrderedDict() | ||
if cursor.description is not None: | ||
for field in cursor.description: | ||
field_dict[field[0]] = self.type_map(field[1]) | ||
csv_writer.writerows(cursor) | ||
with closing(mysql.get_conn()) as conn: | ||
with closing(conn.cursor()) as cursor: | ||
cursor.execute(self.sql) | ||
csv_writer = csv.writer( | ||
f, | ||
delimiter=self.delimiter, | ||
quoting=self.quoting, | ||
quotechar=self.quotechar if self.quoting != csv.QUOTE_NONE else None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was the error. A test testing it was only run with MySQL (mysql_to_hive.py) and it passed empty string as quotechar, and it seems one of the small, undocumented changes in Python 3.11 is that csv writer checks that quotechar is single-character string or None even if quoting is set to "csv.QUOTE_NONE" (so "" is not allowed to be passed as quotechar - and this is what ws passed in the test. I changed it in the way that we ignore quotechar (set it to None) when quoting = csv.QUOTE_NONE. Additionally - the reason why the tests were hanging was that in this case cursors were not closed and there was another cursor in finally of the test that tried to execute query using the same cursor - which caused the cleanup execute SQL hang indefinitely. finally:
with closing(hook.get_conn()) as conn:
with closing(conn.cursor()) as cursor:
cursor.execute(f"DROP TABLE IF EXISTS {mysql_table}") There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can do |
||
escapechar=self.escapechar, | ||
encoding="utf-8", | ||
) | ||
field_dict = OrderedDict() | ||
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() # type: ignore[misc] | ||
self.log.info("Loading file into Hive") | ||
hive.load_file( | ||
f.name, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we supporting Python 3.11 in 2.6.1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope :). Good catch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#31468