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
...@@ -6737,7 +6737,6 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -6737,7 +6737,6 @@ Business Template is a set of definitions, such as skins, portal types and categ
keep_items={'portal_status_message': message}, keep_items={'portal_status_message': message},
abort_transaction=True) abort_transaction=True)
transaction.abort()
raise RuntimeError(message) raise RuntimeError(message)
self.setTemplateModuleComponentIdList(sorted(template_module_component_id_set)) 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 ...@@ -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.setTemplateExtensionIdList(sorted(template_extension_id_set))
self.setTemplateTestIdList(sorted(template_test_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: if list_selection_name is not None:
message = ( return self.Base_redirect(
"All components were successfully imported from filesystem to ZODB. " 'view',
"Please note that imported {Document,Interfaces,Mixin,Tool Components} " keep_items={'portal_status_message': (
"have not been validated automatically as imports must probably be " "All components were successfully imported from filesystem to ZODB. "
"adjusted before deleting them from the filesystem.") "Please note that they have not been validated automatically and "
"imports must probably be adjusted before deleting them from the "
if still_used_list_dict: "filesystem.")})
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})
# Block acquisition on all _item_name_list properties by setting # Block acquisition on all _item_name_list properties by setting
# a default class value to None # a default class value to None
......
...@@ -8250,14 +8250,12 @@ class _LocalTemplateItemMixin: ...@@ -8250,14 +8250,12 @@ class _LocalTemplateItemMixin:
self.assertEqual(component.getTextContent(), sequence['document_data']) self.assertEqual(component.getTextContent(), sequence['document_data'])
self.assertEqual(component.getPortalType(), self.component_portal_type) self.assertEqual(component.getPortalType(), self.component_portal_type)
self.assertEqual(component.getSourceReference(), sequence['document_source_reference']) self.assertEqual(component.getSourceReference(), sequence['document_source_reference'])
if self.component_portal_type in ('Extension Component', 'Test Component'): # Not validated automatically
self.assertEqual(component.getValidationState(), 'validated') self.assertEqual(component.getValidationState(), 'draft')
else: component.validate()
# Not validated automatically self.tic()
self.assertEqual(component.getValidationState(), 'draft') self.assertEqual(component.getValidationState(), 'validated')
component.validate()
self.tic()
self.assertEqual(component.getValidationState(), 'validated')
sequence.edit(document_id=component_id) sequence.edit(document_id=component_id)
def test_BusinessTemplateWithZodbDocumentMigrated(self): def test_BusinessTemplateWithZodbDocumentMigrated(self):
...@@ -8395,95 +8393,6 @@ class _LocalTemplateItemMixin: ...@@ -8395,95 +8393,6 @@ class _LocalTemplateItemMixin:
sequence_list.addSequenceString(sequence_string) sequence_list.addSequenceString(sequence_string)
sequence_list.play(self) 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 from Products.ERP5Type.Core.DocumentComponent import DocumentComponent
# bt5 (instancehome and ZODB Component) and Products # bt5 (instancehome and ZODB Component) and Products
class TestDocumentTemplateItem(_LocalTemplateItemMixin, class TestDocumentTemplateItem(_LocalTemplateItemMixin,
...@@ -8704,12 +8613,6 @@ TestConstraintTemplateItem.test_BusinessTemplateWithZodbDocumentMigrated = \ ...@@ -8704,12 +8613,6 @@ TestConstraintTemplateItem.test_BusinessTemplateWithZodbDocumentMigrated = \
TestConstraintTemplateItem.test_BusinessTemplateUpgradeDocumentFromFilesystemToZodb = \ TestConstraintTemplateItem.test_BusinessTemplateUpgradeDocumentFromFilesystemToZodb = \
skip('Not implemented yet')(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 = \ TestConstraintTemplateItem.test_BusinessTemplateUpgradeProductDocumentFromFilesystemToZodb = \
skip('Not implemented yet')(TestConstraintTemplateItem.test_BusinessTemplateUpgradeProductDocumentFromFilesystemToZodb) skip('Not implemented yet')(TestConstraintTemplateItem.test_BusinessTemplateUpgradeProductDocumentFromFilesystemToZodb)
......
...@@ -48,8 +48,6 @@ class ExtensionComponent(ModuleComponent): ...@@ -48,8 +48,6 @@ class ExtensionComponent(ModuleComponent):
security = ClassSecurityInfo() security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation) security.declareObjectProtected(Permissions.AccessContentsInformation)
do_validate_on_import_from_filesystem = True
@staticmethod @staticmethod
def _getFilesystemPath(): def _getFilesystemPath():
import os.path import os.path
......
...@@ -49,8 +49,6 @@ class TestComponent(ModuleComponent): ...@@ -49,8 +49,6 @@ class TestComponent(ModuleComponent):
security = ClassSecurityInfo() security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation) security.declareObjectProtected(Permissions.AccessContentsInformation)
do_validate_on_import_from_filesystem = True
@staticmethod @staticmethod
def _getFilesystemPath(): def _getFilesystemPath():
import os.path import os.path
......
...@@ -345,13 +345,6 @@ class ComponentMixin(PropertyRecordableMixin, Base): ...@@ -345,13 +345,6 @@ class ComponentMixin(PropertyRecordableMixin, Base):
""" """
return self.getTextContent() 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, security.declareProtected(Permissions.ModifyPortalContent,
'importFromFilesystem') 'importFromFilesystem')
@classmethod @classmethod
...@@ -403,22 +396,6 @@ class ComponentMixin(PropertyRecordableMixin, Base): ...@@ -403,22 +396,6 @@ class ComponentMixin(PropertyRecordableMixin, Base):
text_content=source_code, text_content=source_code,
portal_type=cls.portal_type) 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 return new_component
InitializeClass(ComponentMixin) 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