kapilt / getpaid

Automatically exported from code.google.com/p/getpaid
0 stars 0 forks source link

KeyError in @@manage-getpaid-orders #216

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Load /@@manage-getpaid-orders
2. In my case, I need to display orders from at least the last 3 months to
trigger the problem.

What is the expected output? What do you see instead?
Output : 
Traceback (innermost last):

    * Module ZPublisher.Publish, line 119, in publish
    * Module ZPublisher.mapply, line 88, in mapply
    * Module ZPublisher.Publish, line 42, in call_object
    * Module Products.PloneGetPaid.browser.admin_order, line 302, in __call__
    * Module Products.PloneGetPaid.browser.admin_order, line 283, in update
    * Module Products.PloneGetPaid.browser.admin_order, line 239, in update
    * Module ore.viewlet.core, line 21, in update
    * Module Products.PloneGetPaid._patch, line 44, in update
    * Module zope.formlib.form, line 750, in update
    * Module zope.formlib.form, line 594, in success
    * Module Products.PloneGetPaid.browser.admin_order, line 236, in
handle_filter_action
    * Module getpaid.core.order, line 252, in search
    * Module getpaid.core.order, line 263, in sort
    * Module getpaid.core.order, line 325, in __iter__
    * Module zope.app.container.sample, line 60, in __getitem__

KeyError: '390592646' 

Excepted output : List of all orders, no exception :)

The cause of the KeyError is probably some corruption in my orders (the
order does not exist but getpaid think it exists). 
I was able to fix this by adding a simple try/except KeyError around one
line of code in
http://code.google.com/p/getpaid/source/browse/getpaid.core/trunk/src/getpaid/co
re/order.py
.
I don't have a diff because I changed this on an older version of the file,
but here's what I changed (line 294 or order.py in current revision r1967)

    def __iter__(self):
        for uid in self.uids:
            yield self.storage[ str( uid ) ]

change to : 

    def __iter__(self):
        for uid in self.uids:
            try:
                yield self.storage[ str( uid ) ]
            except KeyError, e:
                pass # If the order is not found, skip it.

I can commit this change if it seems OK, I didn't want to do it first
because I only tested it with an old version.

Original issue reported on code.google.com by jpho...@gmail.com on 9 Sep 2008 at 4:11

GoogleCodeExporter commented 8 years ago
Hmm, it would be good to know what the root cause of the missing/incorrect order
record is. Trapping the error is a fine idea, but rather than just pass-ing I 
would
prefer to see something being written to the event.log indicating the nature of 
the
problem and that fact that an order's details are missing.

Original comment by darryl.d...@gmail.com on 11 Sep 2008 at 1:36

GoogleCodeExporter commented 8 years ago
OK, I've taken a look at the code. If this order number was created with an old
version of getpaid prior to r1006, then it would have been indexed with a
'fufillment_state' index instead of a 'fulfillment_state' index. This affects
order.OrderQuery.fulfillment_state(), so possibly if the order was then altered,
updated, queried against, or deleted with a later version of getpaid, then the 
index
record has been left behind while the order itself has been deleted. This seems 
the
most likely scenario to me, but others may have a better idea :)

Original comment by darryl.d...@gmail.com on 11 Sep 2008 at 2:10