Commit 292af552 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 0ffaf172
...@@ -1183,6 +1183,10 @@ class Catalog(Folder, ...@@ -1183,6 +1183,10 @@ class Catalog(Folder,
security.declarePrivate('getUIDBuffer') security.declarePrivate('getUIDBuffer')
def getUIDBuffer(self, force_new_buffer=False): def getUIDBuffer(self, force_new_buffer=False):
klass = self.__class__ 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 klass._reserved_uid_lock.locked()
assert getattr(self, 'aq_base', None) is not None assert getattr(self, 'aq_base', None) is not None
instance_key = self.getPhysicalPath() instance_key = self.getPhysicalPath()
...@@ -1201,6 +1205,10 @@ class Catalog(Folder, ...@@ -1201,6 +1205,10 @@ class Catalog(Folder,
Produces reserved uids in advance Produces reserved uids in advance
""" """
klass = self.__class__ 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 klass._reserved_uid_lock.locked()
# This checks if the list of local reserved uids was cleared after clearReserved # This checks if the list of local reserved uids was cleared after clearReserved
# had been called. # had been called.
...@@ -1293,6 +1301,10 @@ class Catalog(Folder, ...@@ -1293,6 +1301,10 @@ class Catalog(Folder,
return None return None
klass = self.__class__ 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: try:
klass._reserved_uid_lock.acquire() klass._reserved_uid_lock.acquire()
self.produceUid() 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