Commit ab9e0f93 authored by Vincent Pelletier's avatar Vincent Pelletier

all: Avoid trivial direct calls to {recursiveI,i}mmediateReindexObject

These methods must not be called synchronously:
- they can break catalog by not being careful enough about other
  reindexations which may happen in parallel. See the serialization_tag
  mechanism for more.
- indexation gets executed in the security context of the user causing the
  call, which may lead to an indexation result different from what happens
  when indexation happens with an all-accesses user.
These lines of code (some even commented-out) give a bad example. Replace
them with safe equivalents.
parent f4e93e19
...@@ -113,7 +113,6 @@ class AmortisationRule(RuleMixin): ...@@ -113,7 +113,6 @@ class AmortisationRule(RuleMixin):
setter = getattr(simulation_movement, setter_name) setter = getattr(simulation_movement, setter_name)
setter(value) setter(value)
simulation_movement.edit(start_date=simulation_movement.getStopDate()) simulation_movement.edit(start_date=simulation_movement.getStopDate())
#simulation_movement.immediateReindexObject()
return modified_properties return modified_properties
def updateSimulationMovement(aggregated_movement, calculated_movement, def updateSimulationMovement(aggregated_movement, calculated_movement,
......
...@@ -2642,9 +2642,7 @@ class SimulationTool(BaseTool): ...@@ -2642,9 +2642,7 @@ class SimulationTool(BaseTool):
# m.Movement_zSetDestinationTotalAssetPrice(uid=m.getUid(), total_asset_price = total_asset_price) # m.Movement_zSetDestinationTotalAssetPrice(uid=m.getUid(), total_asset_price = total_asset_price)
# Global reindexing required afterwards in any case: so let us do it now # Global reindexing required afterwards in any case: so let us do it now
# Until we get faster methods (->reindexObject()) # Until we get faster methods (->reindexObject())
#m.immediateReindexObject()
m.reindexObject() m.reindexObject()
#m.activate(priority=7).immediateReindexObject() # Too slow
return result return result
...@@ -2870,7 +2868,6 @@ class SimulationTool(BaseTool): ...@@ -2870,7 +2868,6 @@ class SimulationTool(BaseTool):
) )
else: else:
raise self.MergeDeliveryListError, "Unknown portal type %s" % str(object_to_update.getPortalType()) raise self.MergeDeliveryListError, "Unknown portal type %s" % str(object_to_update.getPortalType())
#object_to_update.immediateReindexObject()
else: else:
raise self.MergeDeliveryListError, "No object to update" raise self.MergeDeliveryListError, "No object to update"
......
...@@ -1659,7 +1659,7 @@ class TestClosingPeriod(AccountingTestCase): ...@@ -1659,7 +1659,7 @@ class TestClosingPeriod(AccountingTestCase):
# now check content of stock table # now check content of stock table
testStockTableContent() testStockTableContent()
balance_transaction.immediateReindexObject() balance_transaction.reindexObject()
self.tic() self.tic()
testStockTableContent() testStockTableContent()
......
...@@ -787,7 +787,7 @@ class TestAccountingRules(TestAccountingRulesMixin, ERP5TypeTestCase): ...@@ -787,7 +787,7 @@ class TestAccountingRules(TestAccountingRulesMixin, ERP5TypeTestCase):
# getTotalPrice uses mysql, so we must make sure the invoice is cataloged # getTotalPrice uses mysql, so we must make sure the invoice is cataloged
# to have correct results # to have correct results
invoice_line.getParentValue().recursiveImmediateReindexObject() self.tic()
self.assertEqual(invoice_line.getTotalPrice(), 100) self.assertEqual(invoice_line.getTotalPrice(), 100)
self.assertEqual(invoice_line.getTotalQuantity(), 10) self.assertEqual(invoice_line.getTotalQuantity(), 10)
......
...@@ -149,7 +149,7 @@ class TestAccounting_l10n_M9(ERP5TypeTestCase): ...@@ -149,7 +149,7 @@ class TestAccounting_l10n_M9(ERP5TypeTestCase):
self.assertEqual(transmission_sheet.getValidationState(), 'draft') self.assertEqual(transmission_sheet.getValidationState(), 'draft')
# add an invoice to the transamission sheet # add an invoice to the transamission sheet
invoice.setAggregateValue(transmission_sheet) invoice.setAggregateValue(transmission_sheet)
invoice.recursiveImmediateReindexObject() self.tic()
self.getWorkflowTool().doActionFor( self.getWorkflowTool().doActionFor(
transmission_sheet, transmission_sheet,
'emit_action') 'emit_action')
......
...@@ -6808,7 +6808,7 @@ class TestBusinessTemplate(BusinessTemplateMixin): ...@@ -6808,7 +6808,7 @@ class TestBusinessTemplate(BusinessTemplateMixin):
self.assertEqual(initial___ac_local_roles_group_id_dict__, self.assertEqual(initial___ac_local_roles_group_id_dict__,
path.__ac_local_roles_group_id_dict__) path.__ac_local_roles_group_id_dict__)
# make sure we can reindexing the object works # make sure we can reindexing the object works
path.recursiveImmediateReindexObject() path.recursiveReindexObject()
self.tic() self.tic()
finally: finally:
# restore state # restore state
......
...@@ -1336,7 +1336,6 @@ class TestInventory(TestOrderMixin, ERP5TypeTestCase): ...@@ -1336,7 +1336,6 @@ class TestInventory(TestOrderMixin, ERP5TypeTestCase):
action = transition_step['action'] action = transition_step['action']
LOG("Transiting '%s' on packing list %s" % (action, transition_step['id']), 0, '') LOG("Transiting '%s' on packing list %s" % (action, transition_step['id']), 0, '')
workflow_tool.doActionFor(transited_pl, action, packing_list_workflow) workflow_tool.doActionFor(transited_pl, action, packing_list_workflow)
transited_pl.recursiveImmediateReindexObject() # XXX
self.tic() self.tic()
for omit_transit in (0,1): for omit_transit in (0,1):
......
...@@ -861,7 +861,7 @@ class TestPackingListMixin(TestOrderMixin): ...@@ -861,7 +861,7 @@ class TestPackingListMixin(TestOrderMixin):
if quantity is None: if quantity is None:
quantity = sequence.get('line_quantity',self.default_quantity) quantity = sequence.get('line_quantity',self.default_quantity)
container_line.edit(quantity=quantity) container_line.edit(quantity=quantity)
container_line.immediateReindexObject() self.tic()
def stepSetContainerFullQuantity(self,sequence=None, sequence_list=None, def stepSetContainerFullQuantity(self,sequence=None, sequence_list=None,
quantity=None,**kw): quantity=None,**kw):
...@@ -882,7 +882,7 @@ class TestPackingListMixin(TestOrderMixin): ...@@ -882,7 +882,7 @@ class TestPackingListMixin(TestOrderMixin):
if not line.hasCellContent(): if not line.hasCellContent():
quantity = line.getQuantity() quantity = line.getQuantity()
container_line.edit(quantity=quantity) container_line.edit(quantity=quantity)
container_line.immediateReindexObject() self.tic()
self.assertEqual(quantity, container_line.getQuantity()) self.assertEqual(quantity, container_line.getQuantity())
self.assertEqual(quantity, container_line.getTotalQuantity()) self.assertEqual(quantity, container_line.getTotalQuantity())
# with variation # with variation
...@@ -903,7 +903,7 @@ class TestPackingListMixin(TestOrderMixin): ...@@ -903,7 +903,7 @@ class TestPackingListMixin(TestOrderMixin):
quantity=old_cell.getQuantity(), quantity=old_cell.getQuantity(),
predicate_category_list=cell_key, predicate_category_list=cell_key,
variation_category_list=cell_key) variation_category_list=cell_key)
cell.immediateReindexObject() self.tic()
self.assertEqual(old_cell.getQuantity(), cell.getQuantity()) self.assertEqual(old_cell.getQuantity(), cell.getQuantity())
self.assertEqual(old_cell.getTotalQuantity(), cell.getTotalQuantity()) self.assertEqual(old_cell.getTotalQuantity(), cell.getTotalQuantity())
......
...@@ -257,7 +257,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor): ...@@ -257,7 +257,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
self.assertEqual([],folder_object_list) self.assertEqual([],folder_object_list)
person = person_module.newContent(id='4',portal_type='Person') person = person_module.newContent(id='4',portal_type='Person')
person_module.recursiveImmediateReindexObject() self.tic()
folder_object_list = [x.getObject().getId() for x in person_module.searchFolder()] folder_object_list = [x.getObject().getId() for x in person_module.searchFolder()]
self.assertEqual(['4'],folder_object_list) self.assertEqual(['4'],folder_object_list)
...@@ -286,7 +286,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor): ...@@ -286,7 +286,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
portal_catalog.manage_catalogClear() portal_catalog.manage_catalogClear()
person = person_module.newContent(id='4',portal_type='Person') person = person_module.newContent(id='4',portal_type='Person')
person_module.recursiveImmediateReindexObject() self.tic()
folder_object_list = [x.getObject().getId() for x in person_module.searchFolder()] folder_object_list = [x.getObject().getId() for x in person_module.searchFolder()]
self.assertEqual(['4'],folder_object_list) self.assertEqual(['4'],folder_object_list)
...@@ -1364,8 +1364,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor): ...@@ -1364,8 +1364,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
# and then delete it # and then delete it
self.deleted_organisation = module.newContent(portal_type='Organisation', self.deleted_organisation = module.newContent(portal_type='Organisation',
title="GreatTitle2") title="GreatTitle2")
self.deleted_organisation.immediateReindexObject() self.tic()
self.commit()
deleted_url = self.deleted_organisation.getRelativeUrl() deleted_url = self.deleted_organisation.getRelativeUrl()
module.manage_delObjects(ids=[self.deleted_organisation.getId()]) module.manage_delObjects(ids=[self.deleted_organisation.getId()])
self.commit() self.commit()
...@@ -1722,7 +1721,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor): ...@@ -1722,7 +1721,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
""" """
org_a = self._makeOrganisation(title='abc',default_address_city='abc') org_a = self._makeOrganisation(title='abc',default_address_city='abc')
module = self.getOrganisationModule() module = self.getOrganisationModule()
module.immediateReindexObject() self.tic()
# First try without aliases # First try without aliases
query1 = Query(parent_portal_type="Organisation") query1 = Query(parent_portal_type="Organisation")
query2 = Query(grand_parent_portal_type="Organisation Module") query2 = Query(grand_parent_portal_type="Organisation Module")
......
...@@ -298,7 +298,7 @@ class TestListBox(ERP5TypeTestCase): ...@@ -298,7 +298,7 @@ class TestListBox(ERP5TypeTestCase):
foo_module = portal.foo_module foo_module = portal.foo_module
o = foo_module.newContent(title=u'\xe9lisa') o = foo_module.newContent(title=u'\xe9lisa')
o.immediateReindexObject() self.tic()
request = get_request() request = get_request()
request['here'] = portal.foo_module request['here'] = portal.foo_module
...@@ -332,7 +332,7 @@ class TestListBox(ERP5TypeTestCase): ...@@ -332,7 +332,7 @@ class TestListBox(ERP5TypeTestCase):
foo_module = portal.foo_module foo_module = portal.foo_module
o = foo_module.newContent(title=u'\xe9lisa') o = foo_module.newContent(title=u'\xe9lisa')
o.immediateReindexObject() self.tic()
request = get_request() request = get_request()
request['here'] = portal.foo_module request['here'] = portal.foo_module
...@@ -389,7 +389,7 @@ class TestListBox(ERP5TypeTestCase): ...@@ -389,7 +389,7 @@ class TestListBox(ERP5TypeTestCase):
self.assertEqual(word in o.getSubjectList(), True) self.assertEqual(word in o.getSubjectList(), True)
# Reindex # Reindex
o.immediateReindexObject() self.tic()
# Render the module in html # Render the module in html
request = get_request() request = get_request()
...@@ -485,7 +485,7 @@ class TestListBox(ERP5TypeTestCase): ...@@ -485,7 +485,7 @@ class TestListBox(ERP5TypeTestCase):
o = foo_module.newContent() o = foo_module.newContent()
# Reindex # Reindex
o.immediateReindexObject() self.tic()
# Render the module in html # Render the module in html
request = get_request() request = get_request()
...@@ -570,7 +570,7 @@ class TestListBox(ERP5TypeTestCase): ...@@ -570,7 +570,7 @@ class TestListBox(ERP5TypeTestCase):
o = foo_module.newContent() o = foo_module.newContent()
# Reindex # Reindex
o.immediateReindexObject() self.tic()
# Render the module in html # Render the module in html
request = get_request() request = get_request()
......
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