bz19823: Another fix for this one.

We need to keep a transaction open before we call calc_max_id and
calc_item_count().  Otherwise if the backend removes an item between
when we calculate them and when we select the item data, the item
data won't be there.