# Buggy code
def _add_temporary_set(self, val):
    """TODO: This method has known issues (see tickets) and needs to be
    reviewed. [JDS 9/2014]"""

    _component_sets = getattr(val, "_implicit_subsets", None)
    #
    # FIXME: The name attribute should begin with "_", and None
    # should replace "_unknown_"
    #
    if _component_sets is not None:
        for ctr, tset in enumerate(_component_sets):
            if tset._name == "_unknown_":
                self._construct_temporary_set(
                    tset, val.local_name + "_index_" + str(ctr)
                )
    if (
        isinstance(val._index, _SetDataBase)
        and val._index.parent_component().local_name == "_unknown_"
    ):
        self._construct_temporary_set(val._index, val.local_name + "_index")
    if (
        isinstance(getattr(val, "initialize", None), _SetDataBase)
        and val.initialize.parent_component().local_name == "_unknown_"
    ):
        self._construct_temporary_set(val.initialize, val.local_name + "_index_init")
    if (
        getattr(val, "domain", None) is not None
        and getattr(val.domain, "local_name", None) == "_unknown_"
    ):
        self._construct_temporary_set(val.domain, val.local_name + "_domain")


# Traceback (AttributeError)
m.v_1 = Var(m.s['s1'], m.s2, initialize=10)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/blnicho/Research/pyomo/pyomo/core/base/var.py", line 471, in __init__
IndexedComponent.__init__(self, *args, **kwd)
File "/home/blnicho/Research/pyomo/pyomo/core/base/indexed_component.py", line 308, in __init__
self._index = tmp[0].cross(*tmp[1:])
AttributeError: '_IndexedSetData' object has no attribute 'cross'
m.v_1 = Var(m.s2, m.s['s1'], initialize=10)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/blnicho/Research/pyomo/pyomo/core/base/block.py", line 542, in __setattr__
self.add_component(name, val)
File "/home/blnicho/Research/pyomo/pyomo/core/base/block.py", line 870, in add_component
self._add_temporary_set(val)
File "/home/blnicho/Research/pyomo/pyomo/core/base/block.py", line 686, in _add_temporary_set
if tset._name == "_unknown_":
AttributeError: '_IndexedSetData' object has no attribute '_name'

# Fixed code
def _add_temporary_set(self, val):
    """TODO: This method has known issues (see tickets) and needs to be
    reviewed. [JDS 9/2014]"""

    _component_sets = getattr(val, "_implicit_subsets", None)
    #
    # FIXME: The name attribute should begin with "_", and None
    # should replace "_unknown_"
    #
    if _component_sets is not None:
        for ctr, tset in enumerate(_component_sets):
            if tset.parent_component()._name == "_unknown_":
                self._construct_temporary_set(
                    tset, val.local_name + "_index_" + str(ctr)
                )
    if (
        isinstance(val._index, _SetDataBase)
        and val._index.parent_component().local_name == "_unknown_"
    ):
        self._construct_temporary_set(val._index, val.local_name + "_index")
    if (
        isinstance(getattr(val, "initialize", None), _SetDataBase)
        and val.initialize.parent_component().local_name == "_unknown_"
    ):
        self._construct_temporary_set(val.initialize, val.local_name + "_index_init")
    if (
        getattr(val, "domain", None) is not None
        and getattr(val.domain, "local_name", None) == "_unknown_"
    ):
        self._construct_temporary_set(val.domain, val.local_name + "_domain")