Skip to content

Commit 3fdf3fb

Browse files
committed
cqle: Handle and return descriptive error for unknown table option
PYTHON-406
1 parent c0087da commit 3fdf3fb

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

cassandra/cqlengine/management.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,10 @@ def _update_options(model):
422422

423423
update_options = {}
424424
for name, value in model_options.items():
425-
existing_value = existing_options[name]
425+
try:
426+
existing_value = existing_options[name]
427+
except KeyError:
428+
raise KeyError("Invalid table option: '%s'; known options: %s" % (name, existing_options.keys()))
426429
if isinstance(existing_value, six.string_types):
427430
if value != existing_value:
428431
update_options[name] = value

tests/integration/cqlengine/management/test_management.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,15 @@ def test_table_property_update(self):
217217

218218
self.assertDictContainsSubset(ModelWithTableProperties.__options__, table_options)
219219

220+
def test_bogus_option_update(self):
221+
sync_table(ModelWithTableProperties)
222+
option = 'no way will this ever be an option'
223+
try:
224+
ModelWithTableProperties.__options__[option] = 'what was I thinking?'
225+
self.assertRaisesRegexp(KeyError, "Invalid table option.*%s.*" % option, sync_table, ModelWithTableProperties)
226+
finally:
227+
ModelWithTableProperties.__options__.pop(option, None)
228+
220229

221230
class SyncTableTests(BaseCassEngTestCase):
222231

0 commit comments

Comments
 (0)