X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=daklib%2Fdbconn.py;h=6317b5844467a260865d5c7c67996eda537d7822;hb=c757aaa7d63b4508ad353a2339507ed837a8e0a3;hp=98b6c7d50eb6a23affaa1f3453e485055ccb7e53;hpb=4f29e33412c9bf42023483ef6f6e8dcf2fbe0dc5;p=dak.git diff --git a/daklib/dbconn.py b/daklib/dbconn.py index 98b6c7d5..6317b584 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -204,7 +204,9 @@ class ORMObject(object): # list value = len(value) elif hasattr(value, 'count'): - # query + # query (but not during validation) + if self.in_validation: + continue value = value.count() else: raise KeyError('Do not understand property %s.' % property) @@ -258,6 +260,8 @@ class ORMObject(object): validation_message = \ "Validation failed because property '%s' must not be empty in object\n%s" + in_validation = False + def validate(self): ''' This function validates the not NULL constraints as returned by @@ -272,8 +276,11 @@ class ORMObject(object): getattr(self, property + '_id') is not None: continue if not hasattr(self, property) or getattr(self, property) is None: - raise DBUpdateError(self.validation_message % \ - (property, str(self))) + # str() might lead to races due to a 2nd flush + self.in_validation = True + message = self.validation_message % (property, str(self)) + self.in_validation = False + raise DBUpdateError(message) @classmethod @session_wrapper @@ -2692,7 +2699,7 @@ class Suite(ORMObject): 'overrides_count'] def not_null_constraints(self): - return ['suite_name', 'version'] + return ['suite_name'] def __eq__(self, val): if isinstance(val, str):