assert primary key exists in record before attempting to delete it
[plcapi.git] / PLC / Persons.py
index 518f53c..7648730 100644 (file)
@@ -19,7 +19,7 @@ from PLC.Table import Row, Table
 from PLC.Roles import Role, Roles
 from PLC.Keys import Key, Keys
 from PLC.Messages import Message, Messages
-from PLC.Storage.AlchemyObj import AlchemyObj
+from PLC.Storage.AlchemyObject import AlchemyObj
 
 class Person(AlchemyObj):
     """
@@ -28,8 +28,10 @@ class Person(AlchemyObj):
     dict. Commit to the database with sync().
     """
 
+    tablename = 'persons'
+
     fields = {
-        'person_id': Parameter(int, "User identifier"),
+        'person_id': Parameter(int, "User identifier", primary_key=True),
         'keystone_id': Parameter(int, "Keystone User identifier"),
         'first_name': Parameter(str, "Given name", max = 128),
         'last_name': Parameter(str, "Surname", max = 128),
@@ -141,6 +143,7 @@ class Person(AlchemyObj):
         
 
     def delete(self):
+        assert 'person_id' in self
         # delete relationships
         SlicePerson().delete.filter({'person_id': self['person_id']})