# Buggy code
def _component_data_iter(self, ctype=None, active=None, sort=False):
    """
    Generator that returns a 3-tuple of (component name, index value,
    and _ComponentData) for every component data in the block.
    """
    _sort_indices = SortComponents.sort_indices(sort)
    _subcomp = PseudoMap(self, ctype, active, sort)
    for name, comp in _subcomp.iteritems():
        # _NOTE_: Suffix has a dict interface (something other
        #         derived non-indexed Components may do as well),
        #         so we don't want to test the existence of
        #         iteritems as a check for components. Also,
        #         the case where we test len(comp) after seeing
        #         that comp.is_indexed is False is a hack for a
        #         SimpleConstraint whose expression resolved to
        #         Constraint.skip or Constraint.feasible (in which
        #         case its data is empty and iteritems would have
        #         been empty as well)
        # try:
        #    _items = comp.iteritems()
        # except AttributeError:
        #    _items = [ (None, comp) ]
        if comp.is_indexed():
            _items = comp.iteritems()
        # This is a hack (see _NOTE_ above).
        elif len(comp) or not hasattr(comp, "_data"):
            _items = ((None, comp),)
        else:
            _items = tuple()

        if _sort_indices:
            _items = sorted(_items, key=itemgetter(0))
        if active is None or not isinstance(comp, ActiveIndexedComponent):
            for idx, compData in _items:
                yield (name, idx), compData
        else:
            for idx, compData in _items:
                if compData.active == active:
                    yield (name, idx), compData


# Traceback (OverflowError)
Traceback (most recent call last):
File "infinite_set_bug.py", line 8, in <module>
for comp in m.component_data_objects():
File "/home/esjohn/src/pyomo/pyomo/core/base/block.py", line 1415, in component_data_objects
sort=sort):
File "/home/esjohn/src/pyomo/pyomo/core/base/block.py", line 1339, in _component_data_iter
elif len(comp) or not hasattr(comp, '_data'):
File "/home/esjohn/src/pyomo/pyomo/core/base/set.py", line 2955, in __len__
"The length of a non-finite Set is Inf; however, Python "
OverflowError: The length of a non-finite Set is Inf; however, Python requires len() to return a non-negative integer value. Check isfinite() before calling len() for possibly infinite Sets

# Fixed code
def _component_data_iter(self, ctype=None, active=None, sort=False):
    """
    Generator that returns a 3-tuple of (component name, index value,
    and _ComponentData) for every component data in the block.
    """
    _sort_indices = SortComponents.sort_indices(sort)
    _subcomp = PseudoMap(self, ctype, active, sort)
    for name, comp in _subcomp.iteritems():
        # NOTE: Suffix has a dict interface (something other derived
        #   non-indexed Components may do as well), so we don't want
        #   to test the existence of iteritems as a check for
        #   component datas. We will rely on is_indexed() to catch
        #   all the indexed components.  Then we will do special
        #   processing for the scalar components to catch the case
        #   where there are "sparse scalar components"
        if comp.is_indexed():
            _items = comp.iteritems()
        elif hasattr(comp, "_data"):
            # This may be an empty Scalar component (e.g., from
            # Constraint.Skip on a scalar Constraint)
            assert len(comp._data) <= 1
            _items = iteritems(comp._data)
        else:
            _items = ((None, comp),)

        if _sort_indices:
            _items = sorted(_items, key=itemgetter(0))
        if active is None or not isinstance(comp, ActiveIndexedComponent):
            for idx, compData in _items:
                yield (name, idx), compData
        else:
            for idx, compData in _items:
                if compData.active == active:
                    yield (name, idx), compData