Ticket #408 (closed defect: fixed)

Opened 2 years ago

Last modified 18 months ago

_object_stack() causes exception if proxy object never had a "push"

Reported by: rcscomp Owned by: ianb
Priority: normal Milestone:
Component: paste Version: released-version
Severity: normal Keywords:
Cc: randy@…

Description

class TestRegistryHasObject(object):

    testsop = StackedObjectProxy(name="testsop")

    

    def test_registry(self):

        assert not registry_has_object(self.testsop)

        foo = ''

        self.testsop._push_object(foo)

        assert registry_has_object(self.testsop)

        self.testsop._pop_object()

        assert not registry_has_object(self.testsop)

This should work, but the first assert throws an exception.

Looking at the code indicates that the following would solve the problem at hand (but it may be better to initialize the ____local__ with .objects instead of catching the exception:

    def _object_stack(self):
        """Returns all of the objects stacked in this container

        (Might return [] if there are none)
        """
        try:
            return self.____local__.objects[:]
        except AssertionError:
            return []
        except AttributeError, e:
            if "object has no attribute 'objects'" not in str(e):
                raise
            return []

Change History

Changed 2 years ago by rcscomp

Sorry, definition for registry_has_object() is:

def registry_has_object(to_check):

    return bool(to_check._object_stack())

Changed 18 months ago by ianb

  • status changed from new to closed
  • resolution set to fixed

Error caught in 1470:1b824e767392

Note: See TracTickets for help on using tickets.