Skip to content

Commit ed085c5

Browse files
mdesmethashhar
authored andcommitted
Add deprecation warning for ROLE{} pattern
1 parent 1dc80fb commit ed085c5

File tree

2 files changed

+33
-25
lines changed

2 files changed

+33
-25
lines changed

tests/unit/test_client.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -94,30 +94,31 @@ def test_request_headers(mock_get_and_post):
9494
client_info_header = constants.HEADER_CLIENT_INFO
9595
client_info_value = "some_client_info"
9696

97-
req = TrinoRequest(
98-
host="coordinator",
99-
port=8080,
100-
client_session=ClientSession(
101-
user=user,
102-
source=source,
103-
catalog=catalog,
104-
schema=schema,
105-
timezone=timezone,
106-
headers={
107-
accept_encoding_header: accept_encoding_value,
108-
client_info_header: client_info_value,
109-
},
110-
roles={
111-
"hive": "ALL",
112-
"system": "analyst",
113-
"catalog1": "NONE",
114-
# ensure backwards compatibility
115-
"catalog2": "ROLE{catalog2_role}",
116-
}
117-
),
118-
http_scheme="http",
119-
redirect_handler=None,
120-
)
97+
with pytest.deprecated_call():
98+
req = TrinoRequest(
99+
host="coordinator",
100+
port=8080,
101+
client_session=ClientSession(
102+
user=user,
103+
source=source,
104+
catalog=catalog,
105+
schema=schema,
106+
timezone=timezone,
107+
headers={
108+
accept_encoding_header: accept_encoding_value,
109+
client_info_header: client_info_value,
110+
},
111+
roles={
112+
"hive": "ALL",
113+
"system": "analyst",
114+
"catalog1": "NONE",
115+
# ensure backwards compatibility
116+
"catalog2": "ROLE{catalog2_role}",
117+
}
118+
),
119+
http_scheme="http",
120+
redirect_handler=None,
121+
)
121122

122123
def assert_headers(headers):
123124
assert headers[constants.HEADER_CATALOG] == catalog

trino/client.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import re
4444
import threading
4545
import urllib.parse
46+
import warnings
4647
from datetime import date, datetime, time, timedelta, timezone, tzinfo
4748
from decimal import Decimal
4849
from time import sleep
@@ -239,7 +240,13 @@ def timezone(self):
239240
def _format_roles(self, roles):
240241
formatted_roles = {}
241242
for catalog, role in roles.items():
242-
if role in ("NONE", "ALL") or ROLE_PATTERN.match(role) is not None:
243+
is_legacy_role_pattern = ROLE_PATTERN.match(role) is not None
244+
if role in ("NONE", "ALL") or is_legacy_role_pattern:
245+
if is_legacy_role_pattern:
246+
warnings.warn(f"A role '{role}' is provided using a legacy format. "
247+
"Please remove the ROLE{} wrapping. Support for the legacy format might be "
248+
"removed in a future release.",
249+
DeprecationWarning)
243250
formatted_roles[catalog] = role
244251
else:
245252
formatted_roles[catalog] = f"ROLE{{{role}}}"

0 commit comments

Comments
 (0)