Skip to content

Commit de8d3fc

Browse files
committed
tests: add column_metadata=None variant for METADATA_CHANGED warning path
The existing test used column_metadata=[] (falsy empty list). The warning branch also triggers for None (attribute absent entirely), which has different semantics — it indicates the field was never set rather than explicitly empty. The new test ensures both falsy forms trigger the warning and update result_metadata_id without touching result_metadata.
1 parent 851fe67 commit de8d3fc

1 file changed

Lines changed: 35 additions & 3 deletions

File tree

tests/unit/test_response_future.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,9 +1214,41 @@ def test_set_result_warns_when_metadata_id_but_no_column_metadata(self):
12141214
# metadata_id is still updated even without column metadata
12151215
assert ps.result_metadata_id == b'new_id'
12161216

1217-
# -------------------------------------------------------------------------
1218-
# _query: per-connection feature gating for skip_meta / result_metadata_id
1219-
# -------------------------------------------------------------------------
1217+
def test_set_result_warns_when_metadata_id_but_column_metadata_is_none(self):
1218+
"""
1219+
Like the empty-list variant above, but column_metadata=None (attribute
1220+
absent rather than explicitly empty). Both None and [] are falsy, so
1221+
the warning branch should be taken and result_metadata_id updated.
1222+
"""
1223+
session = self.make_session()
1224+
pool = session._pools.get.return_value
1225+
connection = Mock(spec=Connection)
1226+
connection.protocol_version = 4
1227+
connection.features = Mock()
1228+
connection.features.use_metadata_id = False
1229+
pool.borrow_connection.return_value = (connection, 1)
1230+
1231+
ps = Mock()
1232+
ps.result_metadata = [('ks', 'tb', 'col', Mock())]
1233+
ps.result_metadata_id = b'old_id'
1234+
1235+
rf = self.make_response_future(session)
1236+
rf.prepared_statement = ps
1237+
rf.send_request()
1238+
1239+
response = self._make_rows_response(
1240+
result_metadata_id=b'new_id',
1241+
column_metadata=None,
1242+
)
1243+
1244+
with self.assertLogs('cassandra.cluster', level='WARNING') as log_ctx:
1245+
rf._set_result(None, None, None, response)
1246+
1247+
assert any('result_metadata_id' in msg for msg in log_ctx.output)
1248+
# result_metadata_id is still updated; result_metadata must not be touched
1249+
assert ps.result_metadata_id == b'new_id'
1250+
1251+
12201252

12211253
def test_query_sets_skip_meta_with_scylla_extension(self):
12221254
"""

0 commit comments

Comments
 (0)