Commit 6bbe51d8 authored by Vincent Pelletier's avatar Vincent Pelletier

ZSQLCatalog: Stop hiding possible duplicates in z_getitem_by_{path,uid}

LIMIT hides duplicates. We want to know if we ever violate the
soft-constraint of path unicity in catalog, so stop setting a LIMIT.
Also, for uid lookup, LIMIT is meaningless as this is ha hard unicity
constraint (must be enforced by relational database for ERP5 to work).

Also, simplify both the DTML and the SQL by having fewer ways to be
invoked (backward-compatible).
parent 667c91df
SELECT <dtml-if uid_only>uid<dtml-else>uid,path</dtml-if> from catalog
WHERE
<dtml-if path_list>
path IN (<dtml-in path_list><dtml-sqlvar sequence-item type="string">
<dtml-if sequence-end><dtml-else>,</dtml-if></dtml-in>)
LIMIT <dtml-sqlvar expr="len(path_list)" type="int">
<dtml-else>
<dtml-sqltest path op=eq type="string">
LIMIT 1
</dtml-if>
SELECT uid, path FROM catalog WHERE <dtml-sqltest column="path" expr="path_list" op=eq type="string" multiple>
......@@ -14,9 +14,7 @@
</item>
<item>
<key> <string>arguments_src</string> </key>
<value> <string>path\r\n
path_list\r\n
uid_only</string> </value>
<value> <string>path_list</string> </value>
</item>
<item>
<key> <string>cache_time_</string> </key>
......
SELECT <dtml-if path_only>path<dtml-else>uid,path</dtml-if> from catalog
WHERE
<dtml-if uid_list>
uid IN (<dtml-in uid_list><dtml-sqlvar sequence-item type="int">
<dtml-if sequence-end><dtml-else>,</dtml-if></dtml-in>)
LIMIT <dtml-sqlvar expr="len(uid_list)" type="int">
<dtml-else>
<dtml-sqltest uid op=eq type="int">
LIMIT 1
</dtml-if>
SELECT uid, path FROM catalog WHERE <dtml-sqltest column="uid" expr="uid_list" op=eq type="int" multiple>
......@@ -14,9 +14,7 @@
</item>
<item>
<key> <string>arguments_src</string> </key>
<value> <string>uid\r\n
uid_list\r\n
path_only</string> </value>
<value> <string>uid_list</string> </value>
</item>
<item>
<key> <string>cache_time_</string> </key>
......
......@@ -886,11 +886,11 @@ class Catalog(Folder,
# It could also have a performance impact for traversals to objects in
# the acquisition context on Zope 2.12 even when it didn't raise a weird
# error.
method = self._getOb(self.getSqlGetitemByUid())
search_result = method(uid = uid)
if len(search_result) > 0:
return search_result[0]
raise KeyError, uid
search_result = self._getOb(self.getSqlGetitemByUid())(uid_list=[uid])
if search_result:
result, = search_result
return result
raise KeyError(uid)
security.declarePrivate('editSchema')
def editSchema(self, names_list):
......@@ -1369,7 +1369,7 @@ class Catalog(Folder,
# exceptional case.
error_message = 'uid %r is shared between %r (catalog) and %r (being indexed) ! This can break relations' % (
uid,
uid_path_dict[uid],
catalog_path,
path,
)
if self.sql_catalog_raise_error_on_uid_check:
......@@ -1600,28 +1600,28 @@ class Catalog(Folder,
security.declarePrivate('getUidDictForPathList')
def getUidDictForPathList(self, path_list):
""" Looks up into catalog table to convert path into uid """
return {
return {
x.path: x.uid
for x in self._getOb(
self.getSqlGetitemByPath()
)(
path=None,
path=None, # BBB
path_list=path_list,
uid_only=False,
uid_only=False, # BBB
)
}
security.declarePrivate('getPathDictForUidList')
def getPathDictForUidList(self, uid_list):
""" Looks up into catalog table to convert uid into path """
return {
return {
x.uid: x.path
for x in self._getOb(
self.getSqlGetitemByUid()
)(
uid=None,
uid=None, # BBB
uid_list=uid_list,
path_only=False,
path_only=False, # BBB
)
}
......
......@@ -58,7 +58,7 @@ class TestSQLCatalog(unittest.TestCase):
# test that our method actually gets called while looking records up by
# uid by raising our own exception
self._catalog.sql_getitem_by_uid = 'z_dummy_lookup_method'
def z_dummy_lookup_method(uid):
def z_dummy_lookup_method(uid_list):
raise MyError('foo')
self._catalog.z_dummy_lookup_method = z_dummy_lookup_method
self.assertRaises(MyError, self._catalog.getRecordForUid, 1)
......
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