Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions cassandra/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
Only valid when using native protocol v4+
"""

_BIND_SENTINEL = object()
"""Sentinel for dict.get() in BoundStatement.bind() to distinguish missing keys from None values."""

NON_ALPHA_REGEX = re.compile('[^a-zA-Z0-9]')
START_BADCHAR_REGEX = re.compile('^[^a-zA-Z0-9]*')
END_BADCHAR_REGEX = re.compile('[^a-zA-Z0-9_]*$')
Expand Down Expand Up @@ -608,15 +611,15 @@ def bind(self, values):

# sort values accordingly
for col in col_meta:
try:
values.append(values_dict[col.name])
except KeyError:
if proto_version >= 4:
values.append(UNSET_VALUE)
else:
raise KeyError(
'Column name `%s` not found in bound dict.' %
(col.name))
val = values_dict.get(col.name, _BIND_SENTINEL)
if val is not _BIND_SENTINEL:
values.append(val)
elif proto_version >= 4:
values.append(UNSET_VALUE)
else:
raise KeyError(
'Column name `%s` not found in bound dict.' %
(col.name))

value_len = len(values)
col_meta_len = len(col_meta)
Expand Down
Loading