Commit 02a45abc authored by Jérome Perrin's avatar Jérome Perrin

CatalogTool: fix upgradeSchema with python scripts

Python scripts can be used as catalog methods, including as "clear catalog"
methods. This was causing error when upgradeSchema was called:

    product/ERP5Catalog/CatalogTool.py", line 1372, in upgradeSchema
      method_list_by_connection_id[method.connection_id].append(method)
    AttributeError: connection_id
parent 16fa2c72
......@@ -1369,7 +1369,8 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
method_list_by_connection_id = defaultdict(list)
for method_id in catalog.sql_clear_catalog:
method = catalog[method_id]
method_list_by_connection_id[method.connection_id].append(method)
if hasattr(aq_base(method), 'connection_id'):
method_list_by_connection_id[method.connection_id].append(method)
# Because we cannot select on deferred connections, _upgradeSchema
# cannot be used on SQL methods using a deferred connection.
......
......@@ -4137,3 +4137,13 @@ class CatalogToolUpgradeSchemaTestCase(ERP5TypeTestCase):
with self.assertRaisesRegexp(ProgrammingError,
r"Table '.*\.table1' doesn't exist"):
self.query_connection_2("SELECT b from table1")
def test_upgradeSchema_python_script(self):
method = self.catalog.newContent(
portal_type="Python Script",
id=self.id(),
body="print('for example, create initial data')")
self.catalog.setSqlClearCatalogList([method.getId()])
self.commit()
self.catalog_tool.upgradeSchema(sql_catalog_id=self.catalog.getId())
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