@@ -78,9 +78,45 @@ class CapitalizedKeyModel(Model):
7878
7979class PrimaryKeysOnlyModel (Model ):
8080
81+ __table_name__ = "primary_keys_only"
8182 __options__ = {'compaction' : {'class' : 'LeveledCompactionStrategy' }}
8283
83- first_ey = columns .Integer (primary_key = True )
84+ first_key = columns .Integer (primary_key = True )
85+ second_key = columns .Integer (primary_key = True )
86+
87+
88+ class PrimaryKeysModelChanged (Model ):
89+
90+ __table_name__ = "primary_keys_only"
91+ __options__ = {'compaction' : {'class' : 'LeveledCompactionStrategy' }}
92+
93+ new_first_key = columns .Integer (primary_key = True )
94+ second_key = columns .Integer (primary_key = True )
95+
96+
97+ class PrimaryKeysModelTypeChanged (Model ):
98+
99+ __table_name__ = "primary_keys_only"
100+ __options__ = {'compaction' : {'class' : 'LeveledCompactionStrategy' }}
101+
102+ first_key = columns .Float (primary_key = True )
103+ second_key = columns .Integer (primary_key = True )
104+
105+
106+ class PrimaryKeysRemovedPk (Model ):
107+
108+ __table_name__ = "primary_keys_only"
109+ __options__ = {'compaction' : {'class' : 'LeveledCompactionStrategy' }}
110+
111+ second_key = columns .Integer (primary_key = True )
112+
113+
114+ class PrimaryKeysAddedClusteringKey (Model ):
115+
116+ __table_name__ = "primary_keys_only"
117+ __options__ = {'compaction' : {'class' : 'LeveledCompactionStrategy' }}
118+
119+ new_first_key = columns .Float (primary_key = True )
84120 second_key = columns .Integer (primary_key = True )
85121
86122
@@ -242,6 +278,21 @@ def test_sync_table_works_with_primary_keys_only_tables(self):
242278 table_meta = management ._get_table_metadata (PrimaryKeysOnlyModel )
243279 self .assertIn ('SizeTieredCompactionStrategy' , table_meta .as_cql_query ())
244280
281+ def test_primary_key_validation (self ):
282+ """
283+ Test to ensure that changes to primary keys throw CQLEngineExceptions
284+
285+ @since 3.2
286+ @jira_ticket PYTHON-532
287+ @expected_result Attempts to modify primary keys throw an exception
288+
289+ @test_category object_mapper
290+ """
291+ sync_table (PrimaryKeysOnlyModel )
292+ self .assertRaises (CQLEngineException , sync_table , PrimaryKeysModelChanged )
293+ self .assertRaises (CQLEngineException , sync_table , PrimaryKeysAddedClusteringKey )
294+ self .assertRaises (CQLEngineException , sync_table , PrimaryKeysRemovedPk )
295+
245296
246297class IndexModel (Model ):
247298
0 commit comments