Commit 76e3c115 authored by Vincent Pelletier's avatar Vincent Pelletier

Base: Fix isAncestryIndexable implementation.

Start checking isSubtreeIndexable on parent document, not on current
document.
This bug broke Trash Bins indexation (and should not affect anything else,
as only Trash Bins prevent content indexation currently).

Extent trash tool unit test to verify actual indexation, and not just
indexability API.
parent e5a706e8
......@@ -121,15 +121,32 @@ class TestTrashTool(ERP5TypeTestCase):
self.assertTrue('fake_bin' in trashbin.getId())
sequence.edit(trash_id=trashbin.getId())
def stepCheckTrashBinIndexable(self, sequence=None, sequence_list=None, **kw ):
def stepCheckTrashBinIndexation(self, sequence=None, sequence_list=None, **kw):
"""
Check trash bin is indexable
Check trash bin is indexable and indexed
"""
trash_id = sequence.get('trash_id')
trash = self.getTrashTool()
trashbin = trash._getOb(trash_id, None)
self.assertTrue(trashbin is not None)
self.assertTrue(trashbin.isIndexable)
self.assertTrue(trash.isSubtreeIndexable())
self.assertFalse(trashbin.isSubtreeIndexable())
trash_uid = trash.getUid()
trashbin_uid = trashbin.getUid()
self.assertNotEqual(trash_uid, None)
self.assertNotEqual(trashbin_uid, None)
self.assertItemsEqual(
[
x.path
for x in self.portal.portal_catalog(
uid=(trash_uid, trashbin_uid),
)
],
[
trash.getPath(),
trashbin.getPath(),
],
)
def stepCheckObjectNotBackup(self, sequence=None, sequence_list=None, **kw):
"""
......@@ -349,7 +366,8 @@ class TestTrashTool(ERP5TypeTestCase):
sequence_string = '\
CheckTrashToolExists \
CreateTrashBin \
CheckTrashBinIndexable \
Tic \
CheckTrashBinIndexation \
'
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self, quiet=quiet)
......@@ -364,7 +382,6 @@ class TestTrashTool(ERP5TypeTestCase):
sequence_string = '\
CheckTrashToolExists \
CreateTrashBin \
CheckTrashBinIndexable \
AddBaseCategory \
AddCategories \
Tic \
......@@ -384,7 +401,6 @@ class TestTrashTool(ERP5TypeTestCase):
sequence_string = '\
CheckTrashToolExists \
CreateTrashBin \
CheckTrashBinIndexable \
AddBaseCategory \
AddCategories \
Tic \
......@@ -405,7 +421,6 @@ class TestTrashTool(ERP5TypeTestCase):
sequence_string = '\
CheckTrashToolExists \
CreateTrashBin \
CheckTrashBinIndexable \
AddBaseCategory \
AddCategories \
Tic \
......@@ -430,7 +445,6 @@ class TestTrashTool(ERP5TypeTestCase):
sequence_string = '\
CheckTrashToolExists \
CreateTrashBin \
CheckTrashBinIndexable \
AddBaseCategory \
AddCategories \
AddSubCategories \
......@@ -454,7 +468,6 @@ class TestTrashTool(ERP5TypeTestCase):
sequence_string = '\
CheckTrashToolExists \
CreateTrashBin \
CheckTrashBinIndexable \
AddFolder \
Tic \
BackupFolderObjectsWithSave \
......
......@@ -2824,7 +2824,7 @@ class Base( CopyContainer,
ancestry: a document may only be indexed if its parent is indexable, and
it's parent's parent, etc until ERP5Site object (inclusive).
"""
node = self.aq_inner
node = self.aq_inner.aq_parent
portal = aq_base(self.getPortalObject())
while True:
is_indexable = node.isSubtreeIndexable()
......
......@@ -354,44 +354,20 @@ class DB(TM):
try:
self.db.query(query)
except OperationalError, m:
if m[0] in query_syntax_error:
raise OperationalError(m[0], '%s: %s' % (m[1], query))
__traceback_info__ = (str(m), query)
if m[0] in hosed_connection and self._use_TM and allow_reconnect:
self._forceReconnection()
return self._query(query, allow_reconnect=False)
if m[0] in lock_error:
raise ConflictError('%s: %s: %s' % (m[0], m[1], query))
if not allow_reconnect and self._use_TM or \
m[0] not in hosed_connection:
LOG('ZMySQLDA', ERROR, 'query failed: %s' % (query,))
raise
# Hm. maybe the db is hosed. Let's restart it.
self._forceReconnection()
self.db.query(query)
raise ConflictError
raise OperationalError
except ProgrammingError, exception:
LOG('ZMySQLDA', ERROR, 'query failed: %s' % (query,))
# XXX sometimes, after a programming error, the database object
# gets fully broken and non-functional. So recover it by
# recreation.
self._forceReconnection()
if exception[0] == ER.PARSE_ERROR:
# You have an error in your SQL syntax
# Replace MySQL brain dead error message with a more meaningful
# one. (MySQL only reports the SQL query *from* the error place,
# which strips important contextual information).
error_text = exception[1]
prefix, suffix = error_text.split("'", 1)
if prefix == "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ":
sql, suffix = suffix.rsplit("'", 1)
try:
line_number = int(suffix.rsplit(' ', 1)[-1])
except TypeError:
pass
else:
reference_sql = query
split_reference_sql = reference_sql.split('\n')
candidate_sql = '\n'.join(split_reference_sql[line_number - 1:])
error_position = len(reference_sql) - len(candidate_sql) + candidate_sql.find(sql)
if error_position > -1:
raise ProgrammingError(exception[0], "%s '%s' HERE '%s' %s" % (prefix, reference_sql[:error_position], reference_sql[error_position:], suffix))
raise exception
__traceback_info__ = (str(exception), query)
# XXX sometimes, after a programming error, the database object
# gets fully broken and non-functional. So recover it by
# recreation.
self._forceReconnection()
raise ProgrammingError
return self.db.store_result()
def query(self, query_string, max_rows=1000):
......
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