Commit 0648368e authored by Ayush Tiwari's avatar Ayush Tiwari

erp5_catalog: Do not use lazy_class objects while generating UIDs

Earlier, class for any Catalog object used to be Products.ZSQLCatalog.SQLCatalog,
but now as we have shifted SQLCatalog to ERP5Catalog, the catalog objects have
lazy_class 'erp5.portal_type.Catalog' as their 1st class in mro. This class
don't have the required attributes.

The lazy_class is dynamic, so its not possible for them to save reserved IDs
as their attributes. So, we use the next class in mro, which would be
class 'Products.ERP5Catalog.ERP5Catalog' and save attributes in it.

Notice that this change of 'self.__klass__' is not required if
we are starting a lock with '_reserved_uid_lock' and then acquire-release it
consicutively in one go(transaction).
parent 07296e17
......@@ -1189,6 +1189,10 @@ class Catalog(Folder,
def getUIDBuffer(self, force_new_buffer=False):
global global_uid_buffer_dict
klass = self.__class__
if klass.__module__ == 'erp5.portal_type':
# For lazy_class object, take the class from mro, rather than relying
# on lazy_class object
klass = self.__class__.mro()[1]
assert klass._reserved_uid_lock.locked()
assert getattr(self, 'aq_base', None) is not None
instance_key = self.getPhysicalPath()
......@@ -1207,6 +1211,10 @@ class Catalog(Folder,
Produces reserved uids in advance
"""
klass = self.__class__
if klass.__module__ == 'erp5.portal_type':
# For lazy_class object, take the class from mro, rather than relying
# on lazy_class object
klass = self.__class__.mro()[1]
assert klass._reserved_uid_lock.locked()
# This checks if the list of local reserved uids was cleared after clearReserved
# had been called.
......@@ -1299,6 +1307,10 @@ class Catalog(Folder,
return None
klass = self.__class__
if klass.__module__ == 'erp5.portal_type':
# For lazy_class object, take the class from mro, rather than relying
# on lazy_class object
klass = self.__class__.mro()[1]
try:
klass._reserved_uid_lock.acquire()
self.produceUid()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment