@@ -335,6 +335,8 @@ class MultipleObjectsReturned(_MultipleObjectsReturned):
335335
336336 __options__ = None
337337
338+ __compute_routing_key__ = True
339+
338340 # the queryset class used for this class
339341 __queryset__ = query .ModelQuerySet
340342 __dmlquery__ = query .DMLQuery
@@ -871,10 +873,14 @@ def _get_polymorphic_base(bases):
871873 partition_keys = OrderedDict (k for k in primary_keys .items () if k [1 ].partition_key )
872874 clustering_keys = OrderedDict (k for k in primary_keys .items () if not k [1 ].partition_key )
873875
874- key_cols = [c for c in partition_keys .values ()]
875- partition_key_index = dict ((col .db_field_name , col ._partition_key_index ) for col in key_cols )
876- key_cql_types = [c .cql_type for c in key_cols ]
877- key_serializer = staticmethod (lambda parts , proto_version : [t .to_binary (p , proto_version ) for t , p in zip (key_cql_types , parts )])
876+ if attrs .get ('__compute_routing_key__' , True ):
877+ key_cols = [c for c in partition_keys .values ()]
878+ partition_key_index = dict ((col .db_field_name , col ._partition_key_index ) for col in key_cols )
879+ key_cql_types = [c .cql_type for c in key_cols ]
880+ key_serializer = staticmethod (lambda parts , proto_version : [t .to_binary (p , proto_version ) for t , p in zip (key_cql_types , parts )])
881+ else :
882+ partition_key_index = {}
883+ key_serializer = staticmethod (lambda parts , proto_version : None )
878884
879885 # setup partition key shortcut
880886 if len (partition_keys ) == 0 :
@@ -998,3 +1004,8 @@ class Model(BaseModel):
9981004 """
9991005 *Optional* Specifies a value for the discriminator column when using model inheritance.
10001006 """
1007+
1008+ __compute_routing_key__ = True
1009+ """
1010+ *Optional* Setting False disables computing the routing key for TokenAwareRouting
1011+ """
0 commit comments