Don't query for resource during stack creation

In Resource.__init__, we unconditionally make a query on the resource
table even if the stack hasn't been stored yet and stack.id is None. The
patch adds a simple conditon to skip it.

Change-Id: Ic8f915d6bb82c95db0a65b029b09b864c1348f3d
Merge "Don't query for resource during stack creation"