From 4a19ab5903f0be6bdc56f98227665cb72e22fddd Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Tue, 5 Jun 2012 10:57:08 +1000 Subject: [PATCH] Make sure the resource exists before trying to update it. Change-Id: I5d8bdc0f4ceff61cab0b909dcaaf8ab5952ba4af Signed-off-by: Angus Salkeld --- heat/engine/resources.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/heat/engine/resources.py b/heat/engine/resources.py index 1f1361beec..e42c7238ae 100644 --- a/heat/engine/resources.py +++ b/heat/engine/resources.py @@ -137,11 +137,14 @@ class Resource(object): except Exception as ex: logger.warn('db error %s' % str(ex)) - elif new_state is not self.CREATE_IN_PROGRESS: - rs = db_api.resource_get(None, self.id) - rs.update_and_save({'state': new_state}) - if rs.stack: - rs.stack.update_and_save({'updated_at': datetime.utcnow()}) + elif self.id is not None: + try: + rs = db_api.resource_get(self.stack.context, self.id) + rs.update_and_save({'state': new_state}) + if rs.stack: + rs.stack.update_and_save({'updated_at': datetime.utcnow()}) + except Exception as ex: + logger.warn('db error %s' % str(ex)) if new_state != self.state: ev = {}