Skip to content

Commit 237d322

Browse files
committed
cqle: correct pk validation when db_field is in use
PYTHON-351
1 parent 062d536 commit 237d322

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

cassandra/cqlengine/models.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,13 @@ def _get_column(cls, name):
451451
"""
452452
return cls._columns[name]
453453

454+
@classmethod
455+
def _get_column_by_db_name(cls, name):
456+
"""
457+
Returns the column, mapped by db_field name
458+
"""
459+
return cls._columns.get(cls._db_map.get(name, name))
460+
454461
def __eq__(self, other):
455462
if self.__class__ != other.__class__:
456463
return False

cassandra/cqlengine/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ class ModelQuerySet(AbstractQuerySet):
841841
def _validate_select_where(self):
842842
""" Checks that a filterset will not create invalid select statement """
843843
# check that there's either a =, a IN or a CONTAINS (collection) relationship with a primary key or indexed field
844-
equal_ops = [self.model._columns.get(w.field) for w in self._where if isinstance(w.operator, EqualsOperator)]
844+
equal_ops = [self.model._get_column_by_db_name(w.field) for w in self._where if isinstance(w.operator, EqualsOperator)]
845845
token_comparison = any([w for w in self._where if isinstance(w.value, Token)])
846846
if not any([w.primary_key or w.index for w in equal_ops]) and not token_comparison and not self._allow_filtering:
847847
raise QueryException(('Where clauses require either =, a IN or a CONTAINS (collection) '

0 commit comments

Comments
 (0)