|
20 | 20 | from pyathena.cursor import Cursor |
21 | 21 | from pyathena.error import DatabaseError, NotSupportedError, ProgrammingError |
22 | 22 | from pyathena.model import AthenaQueryExecution |
| 23 | +from pyathena.util import RetryConfig |
23 | 24 | from tests import ENV |
24 | 25 | from tests.pyathena.conftest import connect |
25 | 26 |
|
@@ -879,6 +880,70 @@ def test_execute_kwargs_override_options(self, cursor): |
879 | 880 | assert from_kwargs == [cursor.query_id] |
880 | 881 | assert cursor.fetchone() == (1,) |
881 | 882 |
|
| 883 | + def test_execute_internal_legacy_kwargs(self, cursor): |
| 884 | + """The private _execute() accepts the pre-3.35 individual keyword arguments. |
| 885 | +
|
| 886 | + Regression test for #734: external callers such as dbt-athena <= 1.10.x |
| 887 | + invoke _execute() directly with individual keywords instead of options. |
| 888 | + """ |
| 889 | + query_id = cursor._execute( |
| 890 | + "SELECT 1", |
| 891 | + parameters=None, |
| 892 | + work_group=ENV.default_work_group, |
| 893 | + s3_staging_dir=None, |
| 894 | + cache_size=0, |
| 895 | + cache_expiration_time=0, |
| 896 | + ) |
| 897 | + query_execution = cursor._poll(query_id) |
| 898 | + assert query_execution.state == AthenaQueryExecution.STATE_SUCCEEDED |
| 899 | + |
| 900 | + def test_execute_internal_legacy_kwargs_passthrough(self): |
| 901 | + """The pre-3.35 _execute() keywords are forwarded to the request (no AWS). |
| 902 | +
|
| 903 | + Regression test for #734: on 3.35.0 this call raised |
| 904 | + ``TypeError: _execute() got an unexpected keyword argument 'work_group'``. |
| 905 | + """ |
| 906 | + cursor = Cursor.__new__(Cursor) # bypass __init__ to avoid AWS calls |
| 907 | + cursor._connection = MagicMock() |
| 908 | + cursor._connection.client.start_query_execution.return_value = { |
| 909 | + "QueryExecutionId": "test_query_id" |
| 910 | + } |
| 911 | + cursor._retry_config = RetryConfig() |
| 912 | + |
| 913 | + with ( |
| 914 | + patch.object( |
| 915 | + Cursor, "_build_start_query_execution_request", return_value={} |
| 916 | + ) as request_mock, |
| 917 | + patch.object(Cursor, "_find_previous_query_id", return_value=None) as cache_mock, |
| 918 | + ): |
| 919 | + query_id = cursor._execute( |
| 920 | + "SELECT 1", |
| 921 | + parameters=None, |
| 922 | + work_group="test_work_group", |
| 923 | + s3_staging_dir="s3://test-bucket/path/", |
| 924 | + cache_size=10, |
| 925 | + cache_expiration_time=100, |
| 926 | + result_reuse_enable=True, |
| 927 | + result_reuse_minutes=5, |
| 928 | + paramstyle="qmark", |
| 929 | + ) |
| 930 | + |
| 931 | + assert query_id == "test_query_id" |
| 932 | + request_mock.assert_called_once_with( |
| 933 | + query="SELECT 1", |
| 934 | + work_group="test_work_group", |
| 935 | + s3_staging_dir="s3://test-bucket/path/", |
| 936 | + result_reuse_enable=True, |
| 937 | + result_reuse_minutes=5, |
| 938 | + execution_parameters=None, |
| 939 | + ) |
| 940 | + cache_mock.assert_called_once_with( |
| 941 | + "SELECT 1", |
| 942 | + "test_work_group", |
| 943 | + cache_size=10, |
| 944 | + cache_expiration_time=100, |
| 945 | + ) |
| 946 | + |
882 | 947 | def test_connection_level_callback(self): |
883 | 948 | """Test connection-level default callback.""" |
884 | 949 | callback_results = [] |
|
0 commit comments