[Zope-dev] Re: possible bug in Catalog.py with keyword index ?

Joachim Schmitz js at aixtraware.de
Mon Jul 23 05:57:03 EDT 2007


Dieter Maurer schrieb:
> Joachim Schmitz wrote at 2007-7-20 10:40 +0200:
> 
> Obviously, you got the wrong mainling list.
> 
> This is not a ZODB problem...
> 
my mistake it should have gone to the zope-dev list.
>> ...
>> I found in Catalog.py updateMetadata around line 306
>>
>>         else:
>>             if data.get(index, 0) != newDataRecord:
>>                 data[index] = newDataRecord
>>
>> the if condition evaluates always to false, cause the data.get(index,0) 
>> accesses the data of the index and not of the metadata field as long as 
>> Zope was not restarted that worked fine.
> 
> The code above should prevent a write (which would grow the storage)
> when in fact nothing changed. And it looks correct.
Yes, but it does not work as exspected.
Here is a more detailed description of our usecase:

In our catalog we have a keyword index "registered_courses" and a 
metadata field "registered_courses". If a student registers a new course 
an event is triggered, which adds the new course to the index.  In our 
event-handler we have:


   res = students_catalog(id = student_id)
   if not res:
       return
   student_rec = res[0]
   registered_courses = getattr(student_rec,'registered_courses',None)
   if not registered_courses:
       registered_courses = []
   #import pdb;pdb.set_trace()
   if event_type == "sys_add_object":
       if course_id not in registered_courses:
           registered_courses.append(course_id)
       else:
           return
   elif registered_courses and event_type == "sys_del_object":
       removed = False
       while course_id in registered_courses:
            removed = True
            registered_courses.remove(course_id)
       if not removed:
            return
       record_data = {}
       for field in self.schema() + self.indexes():
           record_data[field] = getattr(student_rec, field)
       # Add the updated data:
       record_data.update(data)
       self.catalog_object(dict2ob(record_data), student_id)

where dict2obj does just that.

That updates the meta_data only on index_creation, and after a zope 
restart the meta_data for registered_courses only contained the first 
added course. That was because (i asume)

data.get(index, 0) always got the data from the index, and not from the 
meta_data. I could veryfy this by looking at the catalog-record in the 
ZMI. So it neve got to update the meta_data, so the "real" cause for 
this problem is that data.get(index, 0), returns the value of the index 
here and not that of the meta_data.







-- 
Gruß Joachim



More information about the Zope-Dev mailing list