def update(self, **args): error_message = None try: model = self.model for key, value in args.items(): setattr(property, key, value) session.merge(model) session.commit() self.model = model except IntegrityError as e: print(str(e)) error_message = 'Faulty or a duplicate record' except Exception as e: print(str(e)) error_message = str(e) finally: if error_message: session.rollback() raise Exception(error_message) return self.model
def update(self, **args): if hasattr(self, 'property') is False: raise Exception("Property was not loaded") error_message = None try: property = self.property for key, value in args.items(): setattr(property, key, value) # Saving to DB session.merge(property) session.commit() self.property = property except IntegrityError as e: print(str(e)) error_message = 'Faulty or a duplicate record' except Exception as e: print(str(e)) error_message = str(e) finally: if error_message: session.rollback() raise Exception(error_message) return self.property