Commit ab9e0f93 by 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.
1 parent f4e93e19
......@@ -113,7 +113,6 @@ class AmortisationRule(RuleMixin):
setter = getattr(simulation_movement, setter_name)
setter(value)
simulation_movement.edit(start_date=simulation_movement.getStopDate())
#simulation_movement.immediateReindexObject()
return modified_properties
def updateSimulationMovement(aggregated_movement, calculated_movement,
......
......@@ -2642,9 +2642,7 @@ class SimulationTool(BaseTool):
# 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
# Until we get faster methods (->reindexObject())
#m.immediateReindexObject()
m.reindexObject()
#m.activate(priority=7).immediateReindexObject() # Too slow
return result
......@@ -2870,7 +2868,6 @@ class SimulationTool(BaseTool):
)
else:
raise self.MergeDeliveryListError, "Unknown portal type %s" % str(object_to_update.getPortalType())
#object_to_update.immediateReindexObject()
else:
raise self.MergeDeliveryListError, "No object to update"
......
......@@ -1659,7 +1659,7 @@ class TestClosingPeriod(AccountingTestCase):
# now check content of stock table
testStockTableContent()
balance_transaction.immediateReindexObject()
balance_transaction.reindexObject()
self.tic()
testStockTableContent()
......
......@@ -787,7 +787,7 @@ class TestAccountingRules(TestAccountingRulesMixin, ERP5TypeTestCase):
# getTotalPrice uses mysql, so we must make sure the invoice is cataloged
# to have correct results
invoice_line.getParentValue().recursiveImmediateReindexObject()
self.tic()
self.assertEqual(invoice_line.getTotalPrice(), 100)
self.assertEqual(invoice_line.getTotalQuantity(), 10)
......
......@@ -149,7 +149,7 @@ class TestAccounting_l10n_M9(ERP5TypeTestCase):
self.assertEqual(transmission_sheet.getValidationState(), 'draft')
# add an invoice to the transamission sheet
invoice.setAggregateValue(transmission_sheet)
invoice.recursiveImmediateReindexObject()
self.tic()
self.getWorkflowTool().doActionFor(
transmission_sheet,
'emit_action')
......
......@@ -6808,7 +6808,7 @@ class TestBusinessTemplate(BusinessTemplateMixin):
self.assertEqual(initial___ac_local_roles_group_id_dict__,
path.__ac_local_roles_group_id_dict__)
# make sure we can reindexing the object works
path.recursiveImmediateReindexObject()
path.recursiveReindexObject()
self.tic()
finally:
# restore state
......
......@@ -1336,7 +1336,6 @@ class TestInventory(TestOrderMixin, ERP5TypeTestCase):
action = transition_step['action']
LOG("Transiting '%s' on packing list %s" % (action, transition_step['id']), 0, '')
workflow_tool.doActionFor(transited_pl, action, packing_list_workflow)
transited_pl.recursiveImmediateReindexObject() # XXX
self.tic()
for omit_transit in (0,1):
......
......@@ -861,7 +861,7 @@ class TestPackingListMixin(TestOrderMixin):
if quantity is None:
quantity = sequence.get('line_quantity',self.default_quantity)
container_line.edit(quantity=quantity)
container_line.immediateReindexObject()
self.tic()
def stepSetContainerFullQuantity(self,sequence=None, sequence_list=None,
quantity=None,**kw):
......@@ -882,7 +882,7 @@ class TestPackingListMixin(TestOrderMixin):
if not line.hasCellContent():
quantity = line.getQuantity()
container_line.edit(quantity=quantity)
container_line.immediateReindexObject()
self.tic()
self.assertEqual(quantity, container_line.getQuantity())
self.assertEqual(quantity, container_line.getTotalQuantity())
# with variation
......@@ -903,7 +903,7 @@ class TestPackingListMixin(TestOrderMixin):
quantity=old_cell.getQuantity(),
predicate_category_list=cell_key,
variation_category_list=cell_key)
cell.immediateReindexObject()
self.tic()
self.assertEqual(old_cell.getQuantity(), cell.getQuantity())
self.assertEqual(old_cell.getTotalQuantity(), cell.getTotalQuantity())
......
......@@ -257,7 +257,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
self.assertEqual([],folder_object_list)
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()]
self.assertEqual(['4'],folder_object_list)
......@@ -286,7 +286,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
portal_catalog.manage_catalogClear()
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()]
self.assertEqual(['4'],folder_object_list)
......@@ -1364,8 +1364,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
# and then delete it
self.deleted_organisation = module.newContent(portal_type='Organisation',
title="GreatTitle2")
self.deleted_organisation.immediateReindexObject()
self.commit()
self.tic()
deleted_url = self.deleted_organisation.getRelativeUrl()
module.manage_delObjects(ids=[self.deleted_organisation.getId()])
self.commit()
......@@ -1722,7 +1721,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
"""
org_a = self._makeOrganisation(title='abc',default_address_city='abc')
module = self.getOrganisationModule()
module.immediateReindexObject()
self.tic()
# First try without aliases
query1 = Query(parent_portal_type="Organisation")
query2 = Query(grand_parent_portal_type="Organisation Module")
......
......@@ -298,7 +298,7 @@ class TestListBox(ERP5TypeTestCase):
foo_module = portal.foo_module
o = foo_module.newContent(title=u'\xe9lisa')
o.immediateReindexObject()
self.tic()
request = get_request()
request['here'] = portal.foo_module
......@@ -332,7 +332,7 @@ class TestListBox(ERP5TypeTestCase):
foo_module = portal.foo_module
o = foo_module.newContent(title=u'\xe9lisa')
o.immediateReindexObject()
self.tic()
request = get_request()
request['here'] = portal.foo_module
......@@ -389,7 +389,7 @@ class TestListBox(ERP5TypeTestCase):
self.assertEqual(word in o.getSubjectList(), True)
# Reindex
o.immediateReindexObject()
self.tic()
# Render the module in html
request = get_request()
......@@ -485,7 +485,7 @@ class TestListBox(ERP5TypeTestCase):
o = foo_module.newContent()
# Reindex
o.immediateReindexObject()
self.tic()
# Render the module in html
request = get_request()
......@@ -570,7 +570,7 @@ class TestListBox(ERP5TypeTestCase):
o = foo_module.newContent()
# Reindex
o.immediateReindexObject()
self.tic()
# Render the module in html
request = get_request()
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!