Skip to content

Commit 89a3211

Browse files
Copilotmykaul
andcommitted
Restore decode_val function for readability and remove unused import
Per review feedback: - Restored decode_val function in encryption path for better readability - Keeps the structure similar to original code but without redundant policy check - Removed unused MagicMock import from test file The optimization remains the same: contains_column() called once per column. Co-authored-by: mykaul <[email protected]>
1 parent 12eac38 commit 89a3211

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

cassandra/protocol.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -730,13 +730,13 @@ def recv_results_rows(self, f, protocol_version, user_type_map, result_metadata,
730730
for col_desc in col_descs
731731
]
732732

733+
def decode_val(val, col_md, uses_ce, col_desc):
734+
col_type = column_encryption_policy.column_type(col_desc) if uses_ce else col_md[3]
735+
raw_bytes = column_encryption_policy.decrypt(col_desc, val) if uses_ce else val
736+
return col_type.from_binary(raw_bytes, protocol_version)
737+
733738
def decode_row(row):
734-
return tuple(
735-
column_encryption_policy.column_type(col_desc).from_binary(
736-
column_encryption_policy.decrypt(col_desc, val), protocol_version
737-
) if uses_ce else col_md[3].from_binary(val, protocol_version)
738-
for val, col_md, (uses_ce, col_desc) in zip(row, column_metadata, column_encryption_info)
739-
)
739+
return tuple(decode_val(val, col_md, uses_ce, col_desc) for val, col_md, (uses_ce, col_desc) in zip(row, column_metadata, column_encryption_info))
740740
else:
741741
# Simple path without encryption - just decode raw bytes directly
742742
def decode_row(row):

tests/unit/test_protocol_decode_optimization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
import unittest
16-
from unittest.mock import Mock, MagicMock
16+
from unittest.mock import Mock
1717
import io
1818

1919
from cassandra import ProtocolVersion

0 commit comments

Comments
 (0)