Forum OpenACS Development: Slightly broken acs_object_context_index

I almost have the tree_sortkey upgrade script working but it was failing in a wierd way...

I found an inconsistency between acs_objects and acs_object_context_index on a pretty new install...

clean=# select * from acs_object_context_index where object_id in (-400,183527) order by object_id, n_generations;
 object_id | ancestor_id | n_generations 
-----------+-------------+---------------
      -400 |        -400 |             0
      -400 |           0 |             1
      -400 |          -4 |             2
    183527 |      183527 |             0
    183527 |          -4 |             1
(5 rows)
but in acs_objects the context_id of 183527 is 0:
 select context_id, object_id from acs_objects where object_id in (-400,183527, -4);
 context_id | object_id 
------------+-----------
          0 |      -400
          0 |    183527
            |        -4
I checked openacs.org and found one occurance of the same thing....
select * from  acs_object_context_index where object_id in (391,16
 object_id | ancestor_id | n_generations
-----------+-------------+---------------
       391 |           0 |             1
       391 |         391 |             0
       168 |           0 |             2
       168 |          -3 |             1
       168 |         168 |             0

select object_id, context_id from acs_objects where object_id in (168,391);
 object_id | context_id
-----------+------------
       168 |         -3
       391 |         -3

Anyway, I can generate the tree_sortkeys a different way but this is something we should probably investigate more and fix.

(also, the first site was a very recent install so it's not an upgrade script issue).