Commit 799da311 authored by Arnaud Fontaine's avatar Arnaud Fontaine

ZODB Components: Do not validate nor check {consistency,source code} after importing from FS.

* pylint may return a false positive error which have to be disabled and
  failing to import it because of that requires to edit on the FS and try
  again so it is not practical for a whole Product. Instead it is easier
  to import it and not validate
* Validation was done only for 'Test Component' and 'Extension Component',
  but all imported Components had their consistency and source code checked
  and this is not consistent to not validate but do these checks.
* importFromFilesystem() was checking consistency and source code, and this
  was done again when validating.

So leave the imported ZODB Components as draft and let the developer fixes
issues upon validation before committing.
parent f675c0fb
Pipeline #6282 passed with stage
in 0 seconds
......@@ -6737,7 +6737,6 @@ Business Template is a set of definitions, such as skins, portal types and categ
keep_items={'portal_status_message': message},
abort_transaction=True)
transaction.abort()
raise RuntimeError(message)
self.setTemplateModuleComponentIdList(sorted(template_module_component_id_set))
......@@ -6748,45 +6747,14 @@ Business Template is a set of definitions, such as skins, portal types and categ
self.setTemplateExtensionIdList(sorted(template_extension_id_set))
self.setTemplateTestIdList(sorted(template_test_id_set))
# This will trigger a reset so that Portal Types mro() can be checked
# after migration for filesystem Products modules still being used
#
# TODO-arnau: checkPythonSource code done twice (importFromFilesystem()
# and newContent() through Interaction Workflow)
transaction.commit()
still_used_list_dict = {}
for _, cls_module, _ in self._getAllFilesystemModuleFromPortalTypeIdList(
portal.portal_types.objectIds()):
if cls_module in migrated_product_module_set:
package, module = cls_module.rsplit('.', 1)
still_used_list_dict.setdefault(package, []).append(module)
if still_used_list_dict:
module_still_used_message = ', '.join(
[ "%s.{%s}" % (package, ','.join(sorted(module_list)))
for package, module_list in still_used_list_dict.iteritems() ])
LOG('BusinessTemplate',
WARNING,
"The following Documents are still being imported so code need to "
"be updated: " + module_still_used_message)
if list_selection_name is not None:
message = (
"All components were successfully imported from filesystem to ZODB. "
"Please note that imported {Document,Interfaces,Mixin,Tool Components} "
"have not been validated automatically as imports must probably be "
"adjusted before deleting them from the filesystem.")
if still_used_list_dict:
message = (
message +
" WARNING: Some migrated Documents have their filesystem Document "
"still being imported so code need to be updated (see log file).")
return self.Base_redirect('view',
keep_items={'portal_status_message': message})
return self.Base_redirect(
'view',
keep_items={'portal_status_message': (
"All components were successfully imported from filesystem to ZODB. "
"Please note that they have not been validated automatically and "
"imports must probably be adjusted before deleting them from the "
"filesystem.")})
# Block acquisition on all _item_name_list properties by setting
# a default class value to None
......
......@@ -8250,14 +8250,12 @@ class _LocalTemplateItemMixin:
self.assertEqual(component.getTextContent(), sequence['document_data'])
self.assertEqual(component.getPortalType(), self.component_portal_type)
self.assertEqual(component.getSourceReference(), sequence['document_source_reference'])
if self.component_portal_type in ('Extension Component', 'Test Component'):
self.assertEqual(component.getValidationState(), 'validated')
else:
# Not validated automatically
self.assertEqual(component.getValidationState(), 'draft')
component.validate()
self.tic()
self.assertEqual(component.getValidationState(), 'validated')
# Not validated automatically
self.assertEqual(component.getValidationState(), 'draft')
component.validate()
self.tic()
self.assertEqual(component.getValidationState(), 'validated')
sequence.edit(document_id=component_id)
def test_BusinessTemplateWithZodbDocumentMigrated(self):
......@@ -8395,95 +8393,6 @@ class _LocalTemplateItemMixin:
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
def stepCheckDocumentMigrationFailWithConsistencyError(self, sequence=None, **kw):
current_bt = sequence['current_bt']
self.assertRaises(RuntimeError,
current_bt.migrateSourceCodeFromFilesystem,
# version must not start with '_'
version='_invalid_version')
def test_BusinessTemplateUpgradeDocumentFromFilesystemToZodbWithConsistencyError(self):
"""
Check that component.checkConsistency() (called before "validating" a ZODB
Component) is done when migrating Document from filesystem to ZODB
"""
sequence_list = SequenceList()
sequence_string = """
CreateDocument
CreateNewBusinessTemplate
UseExportBusinessTemplate
AddDocumentToBusinessTemplate
CheckModifiedBuildingState
CheckNotInstalledInstallationState
BuildBusinessTemplate
CheckBuiltBuildingState
CheckNotInstalledInstallationState
CheckObjectPropertiesInBusinessTemplate
UseCurrentBusinessTemplateForInstall
InstallWithoutForceBusinessTemplate
Tic
CheckInstalledInstallationState
CheckBuiltBuildingState
CheckSkinsLayers
CheckDocumentExists
CopyBusinessTemplate
CheckDocumentMigrationFailWithConsistencyError
"""
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
def stepCheckDocumentMigrationFailWithSourceCodeError(self, sequence=None, **kw):
current_bt = sequence['current_bt']
from Products.ERP5Type.mixin.component import ComponentMixin
orig_checkSourceCode = ComponentMixin.checkSourceCode
try:
ComponentMixin.checkSourceCode = lambda *args, **kwargs: [
{'type': 'E', 'row': 1, 'column': 1,
'text': 'Source Code Error for Unit Test'}]
self.assertRaises(RuntimeError, current_bt.migrateSourceCodeFromFilesystem,
version='erp5')
ComponentMixin.checkSourceCode = lambda *args, **kwargs: [
{'type': 'F', 'row': 1, 'column': 1,
'text': 'Source Code Error for Unit Test'}]
self.assertRaises(RuntimeError, current_bt.migrateSourceCodeFromFilesystem,
version='erp5')
finally:
ComponentMixin.checkSourceCode = orig_checkSourceCode
def test_BusinessTemplateUpgradeDocumentFromFilesystemToZodbWithSyntaxError(self):
"""
Check that component.checkSourceCode() (called before "validating" a ZODB
Component) is done when migrating Document from filesystem to ZODB
"""
sequence_list = SequenceList()
sequence_string = """
CreateDocument
CreateNewBusinessTemplate
UseExportBusinessTemplate
AddDocumentToBusinessTemplate
CheckModifiedBuildingState
CheckNotInstalledInstallationState
BuildBusinessTemplate
CheckBuiltBuildingState
CheckNotInstalledInstallationState
CheckObjectPropertiesInBusinessTemplate
UseCurrentBusinessTemplateForInstall
InstallWithoutForceBusinessTemplate
Tic
CheckInstalledInstallationState
CheckBuiltBuildingState
CheckSkinsLayers
CheckDocumentExists
CopyBusinessTemplate
CheckDocumentMigrationFailWithSourceCodeError
"""
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
from Products.ERP5Type.Core.DocumentComponent import DocumentComponent
# bt5 (instancehome and ZODB Component) and Products
class TestDocumentTemplateItem(_LocalTemplateItemMixin,
......@@ -8704,12 +8613,6 @@ TestConstraintTemplateItem.test_BusinessTemplateWithZodbDocumentMigrated = \
TestConstraintTemplateItem.test_BusinessTemplateUpgradeDocumentFromFilesystemToZodb = \
skip('Not implemented yet')(TestConstraintTemplateItem.test_BusinessTemplateUpgradeDocumentFromFilesystemToZodb)
TestConstraintTemplateItem.test_BusinessTemplateUpgradeDocumentFromFilesystemToZodbWithConsistencyError = \
skip('Not implemented yet')(TestConstraintTemplateItem.test_BusinessTemplateUpgradeDocumentFromFilesystemToZodbWithConsistencyError)
TestConstraintTemplateItem.test_BusinessTemplateUpgradeDocumentFromFilesystemToZodbWithSyntaxError = \
skip('Not implemented yet')(TestConstraintTemplateItem.test_BusinessTemplateUpgradeDocumentFromFilesystemToZodbWithSyntaxError)
TestConstraintTemplateItem.test_BusinessTemplateUpgradeProductDocumentFromFilesystemToZodb = \
skip('Not implemented yet')(TestConstraintTemplateItem.test_BusinessTemplateUpgradeProductDocumentFromFilesystemToZodb)
......
......@@ -48,8 +48,6 @@ class ExtensionComponent(ModuleComponent):
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
do_validate_on_import_from_filesystem = True
@staticmethod
def _getFilesystemPath():
import os.path
......
......@@ -49,8 +49,6 @@ class TestComponent(ModuleComponent):
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
do_validate_on_import_from_filesystem = True
@staticmethod
def _getFilesystemPath():
import os.path
......
......@@ -345,13 +345,6 @@ class ComponentMixin(PropertyRecordableMixin, Base):
"""
return self.getTextContent()
# Whether ZODB Components is going to be validated or not should depend on
# its types because it is fine to validate '{Test,Extension} Component' as
# it not going to break anything but not for {Document,Interface,Mixin,Tool}
# Components...
do_validate_on_import_from_filesystem = False
security.declareProtected(Permissions.ModifyPortalContent,
'importFromFilesystem')
@classmethod
......@@ -403,22 +396,6 @@ class ComponentMixin(PropertyRecordableMixin, Base):
text_content=source_code,
portal_type=cls.portal_type)
# XXX-ARNAU: checkConsistency() is also called before commit in
# Component_checkSourceCodeAndValidateAfterModified. Also, everything
# should be done in checkConsistency()...
error_message_list = [ m for m in new_component.checkSourceCode()
if m['type'] in ('F', 'E') ]
if error_message_list:
raise SyntaxError(error_message_list)
consistency_message_list = new_component.checkConsistency()
if consistency_message_list:
from Products.DCWorkflow.DCWorkflow import ValidationFailed
raise ValidationFailed(consistency_message_list)
if cls.do_validate_on_import_from_filesystem:
new_component.validate()
return new_component
InitializeClass(ComponentMixin)
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