Comment 2 for bug 1416917

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to heat (master)

Reviewed: https://review.openstack.org/152071
Committed: https://git.openstack.org/cgit/openstack/heat/commit/?id=734f777da48cc008d8da4bf197c7a87a03be8846
Submitter: Jenkins
Branch: master

commit 734f777da48cc008d8da4bf197c7a87a03be8846
Author: Angus Salkeld <email address hidden>
Date: Mon Feb 2 13:12:48 2015 +1000

    Use "if stack is not None" and not "if stack"

    Problem:
    If a nested stack has no resources, then we do not get
    a "nested" link in the resource information returned by
    our API.

    Why?
    In engine/api.py we have:

    if (hasattr(resource, 'nested') and callable(resource.nested) and
                resource.nested()):
             res[rpc_api.RES_NESTED_STACK_ID] = dict(resource.nested().identifier())

    The problem with this is the python definition of False, from the docs:

    "instances of user-defined classes, if the class defines a __nonzero__()
     or __len__() method, when that method returns the integer zero or bool
     value False. [1]"

    So if you have a stack with zero resources (len() returns 0), the
    stack will be False :-O

    Solution:
    Use "if stack is not None:" instead of "if stack".

    Change-Id: Ibdd1cb5dee6ce8e58f7d8f2586a495caded79134
    Closes-bug: 1416917