Skip to content

Commit ac5d0a4

Browse files
authored
Merge pull request scylladb#876 from datastax/python-846
PYTHON-846: Fix DeprecationWarning of log.warn
2 parents aaccf2f + cc1571e commit ac5d0a4

6 files changed

Lines changed: 27 additions & 24 deletions

File tree

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Bug Fixes
1414
Other
1515
-----
1616
* cqlengine: avoid warning when unregistering connection on shutdown (PYTHON-865)
17+
* Fix DeprecationWarning of log.warn (PYTHON-846)
1718

1819
3.12.0
1920
======

cassandra/cluster.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ def __init__(self,
889889
if self._config_mode is _ConfigMode.PROFILES:
890890
default_lbp_profiles = self.profile_manager._profiles_without_explicit_lbps()
891891
if default_lbp_profiles:
892-
log.warn(
892+
log.warning(
893893
'Cluster.__init__ called with contact_points '
894894
'specified, but load-balancing policies are not '
895895
'specified in some ExecutionProfiles. In the next '
@@ -900,7 +900,7 @@ def __init__(self,
900900
''.format(cp=contact_points, eps=default_lbp_profiles))
901901
else:
902902
if load_balancing_policy is None:
903-
log.warn(
903+
log.warning(
904904
'Cluster.__init__ called with contact_points '
905905
'specified, but no load_balancing_policy. In the next '
906906
'major version, this will raise an error; please '
@@ -1053,7 +1053,7 @@ def add_execution_profile(self, name, profile, pool_wait_timeout=5):
10531053
self._contact_points_explicit and not
10541054
profile._load_balancing_policy_explicit)
10551055
if contact_points_but_no_lbp:
1056-
log.warn(
1056+
log.warning(
10571057
'Tried to add an ExecutionProfile with name {name}. '
10581058
'{self} was explicitly configured with contact_points, but '
10591059
'{ep} was not explicitly configured with a '

cassandra/cqltypes.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -971,12 +971,14 @@ def _make_udt_tuple_type(cls, name, field_names):
971971
except ValueError:
972972
try:
973973
t = namedtuple(name, util._positional_rename_invalid_identifiers(field_names))
974-
log.warn("could not create a namedtuple for '%s' because one or more field names are not valid Python identifiers (%s); " \
975-
"returning positionally-named fields" % (name, field_names))
974+
log.warning("could not create a namedtuple for '%s' because one or more "
975+
"field names are not valid Python identifiers (%s); "
976+
"returning positionally-named fields" % (name, field_names))
976977
except ValueError:
977978
t = None
978-
log.warn("could not create a namedtuple for '%s' because the name is not a valid Python identifier; " \
979-
"will return tuples in its place" % (name,))
979+
log.warning("could not create a namedtuple for '%s' because the name is "
980+
"not a valid Python identifier; will return tuples in "
981+
"its place" % (name,))
980982
return t
981983

982984

cassandra/timestamps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def _maybe_warn(self, now):
100100
(diff >= self.warning_threshold * 1e6) and
101101
(since_last_warn >= self.warning_interval * 1e6))
102102
if warn:
103-
log.warn(
103+
log.warning(
104104
"Clock skew detected: current tick ({now}) was {diff} "
105105
"microseconds behind the last generated timestamp "
106106
"({last}), returned timestamps will be artificially "

tests/unit/test_cluster.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,8 @@ def test_warning_on_no_lbp_with_contact_points_profile_mode(self):
404404
def _check_warning_on_no_lbp_with_contact_points(self, cluster_kwargs):
405405
with patch('cassandra.cluster.log') as patched_logger:
406406
Cluster(**cluster_kwargs)
407-
patched_logger.warn.assert_called_once()
408-
warning_message = patched_logger.warn.call_args[0][0]
407+
patched_logger.warning.assert_called_once()
408+
warning_message = patched_logger.warning.call_args[0][0]
409409
self.assertIn('please specify a load-balancing policy', warning_message)
410410
self.assertIn("contact_points = ['127.0.0.1']", warning_message)
411411

@@ -459,7 +459,7 @@ def _check_no_warning_on_contact_points_with_lbp(self, cluster_kwargs):
459459
"""
460460
with patch('cassandra.cluster.log') as patched_logger:
461461
Cluster(**cluster_kwargs)
462-
patched_logger.warn.assert_not_called()
462+
patched_logger.warning.assert_not_called()
463463

464464
@mock_session_pools
465465
def test_warning_adding_no_lbp_ep_to_cluster_with_contact_points(self):
@@ -473,8 +473,8 @@ def test_warning_adding_no_lbp_ep_to_cluster_with_contact_points(self):
473473
profile=ExecutionProfile()
474474
)
475475

476-
patched_logger.warn.assert_called_once()
477-
warning_message = patched_logger.warn.call_args[0][0]
476+
patched_logger.warning.assert_called_once()
477+
warning_message = patched_logger.warning.call_args[0][0]
478478
self.assertIn('no_lbp', warning_message)
479479
self.assertIn('trying to add', warning_message)
480480
self.assertIn('please specify a load-balancing policy', warning_message)
@@ -491,4 +491,4 @@ def test_no_warning_adding_lbp_ep_to_cluster_with_contact_points(self):
491491
profile=ExecutionProfile(load_balancing_policy=Mock(name='lbp'))
492492
)
493493

494-
patched_logger.warn.assert_not_called()
494+
patched_logger.warning.assert_not_called()

tests/unit/test_timestamps.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,12 @@ def test_basic_log_content(self):
131131
tsg._last_warn = 12
132132

133133
tsg._next_timestamp(20, tsg.last)
134-
self.assertEqual(len(self.patched_timestamp_log.warn.call_args_list), 0)
134+
self.assertEqual(len(self.patched_timestamp_log.warning.call_args_list), 0)
135135
tsg._next_timestamp(16, tsg.last)
136136

137-
self.assertEqual(len(self.patched_timestamp_log.warn.call_args_list), 1)
137+
self.assertEqual(len(self.patched_timestamp_log.warning.call_args_list), 1)
138138
self.assertLastCallArgRegex(
139-
self.patched_timestamp_log.warn.call_args,
139+
self.patched_timestamp_log.warning.call_args,
140140
r'Clock skew detected:.*\b16\b.*\b4\b.*\b20\b'
141141
)
142142

@@ -154,7 +154,7 @@ def test_disable_logging(self):
154154

155155
no_warn_tsg.last = 100
156156
no_warn_tsg._next_timestamp(99, no_warn_tsg.last)
157-
self.assertEqual(len(self.patched_timestamp_log.warn.call_args_list), 0)
157+
self.assertEqual(len(self.patched_timestamp_log.warning.call_args_list), 0)
158158

159159
def test_warning_threshold_respected_no_logging(self):
160160
"""
@@ -171,7 +171,7 @@ def test_warning_threshold_respected_no_logging(self):
171171
)
172172
tsg.last, tsg._last_warn = 100, 97
173173
tsg._next_timestamp(98, tsg.last)
174-
self.assertEqual(len(self.patched_timestamp_log.warn.call_args_list), 0)
174+
self.assertEqual(len(self.patched_timestamp_log.warning.call_args_list), 0)
175175

176176
def test_warning_threshold_respected_logs(self):
177177
"""
@@ -189,7 +189,7 @@ def test_warning_threshold_respected_logs(self):
189189
)
190190
tsg.last, tsg._last_warn = 100, 97
191191
tsg._next_timestamp(98, tsg.last)
192-
self.assertEqual(len(self.patched_timestamp_log.warn.call_args_list), 1)
192+
self.assertEqual(len(self.patched_timestamp_log.warning.call_args_list), 1)
193193

194194
def test_warning_interval_respected_no_logging(self):
195195
"""
@@ -207,10 +207,10 @@ def test_warning_interval_respected_no_logging(self):
207207
)
208208
tsg.last = 100
209209
tsg._next_timestamp(70, tsg.last)
210-
self.assertEqual(len(self.patched_timestamp_log.warn.call_args_list), 1)
210+
self.assertEqual(len(self.patched_timestamp_log.warning.call_args_list), 1)
211211

212212
tsg._next_timestamp(71, tsg.last)
213-
self.assertEqual(len(self.patched_timestamp_log.warn.call_args_list), 1)
213+
self.assertEqual(len(self.patched_timestamp_log.warning.call_args_list), 1)
214214

215215
def test_warning_interval_respected_logs(self):
216216
"""
@@ -229,10 +229,10 @@ def test_warning_interval_respected_logs(self):
229229
)
230230
tsg.last = 100
231231
tsg._next_timestamp(70, tsg.last)
232-
self.assertEqual(len(self.patched_timestamp_log.warn.call_args_list), 1)
232+
self.assertEqual(len(self.patched_timestamp_log.warning.call_args_list), 1)
233233

234234
tsg._next_timestamp(72, tsg.last)
235-
self.assertEqual(len(self.patched_timestamp_log.warn.call_args_list), 2)
235+
self.assertEqual(len(self.patched_timestamp_log.warning.call_args_list), 2)
236236

237237

238238
class TestTimestampGeneratorMultipleThreads(unittest.TestCase):

0 commit comments

Comments
 (0)