Ticket #420 (new defect)

Opened 2 years ago

Last modified 2 years ago

suds.xsd.sxbase.SchemaObject item access bug

Reported by: jurko Owned by: jortel
Priority: minor Milestone: 0.4
Component: wsdl/schema Version: 0.4
Keywords: Cc:
Blocked By: Blocking:

Description

suds.xsd.SchemaObject has a __getitem__() function with a bug causing it to only return the initial element (index 0) correctly and return None for any other index.

Original code:

    def __getitem__(self, index):
        i = 0
        for c in self:
            if i == index:
                return c

Suggested code:

    def __getitem__(self, index):
        """Returns a contained schema object referenced by its 0-based index.

        Returns None if such an object does not exist.

        """
        i = 0
        for c in self:
            if i == index:
                return c
            i += 1

There are other possible issues to consider here like efficiency, rasing IndexError when the specified index is out of scope, etc. but I do not think this issue report is the place to get into them and this patch just tries to 'fix the bug' without changing the original function's intended behaviour.

Best regards, Jurko Gospodnetić

Change History

comment:1 Changed 2 years ago by jurko

  • Summary changed from suds.xsd.SchemaObject does not access its items by index correctly to suds.xsd.sxbase.SchemaObject item access bug
Note: See TracTickets for help on using tickets.