Skip to content

Commit

Permalink
Merge pull request #390 from plone/fix_copier_with_broken_relations
Browse files Browse the repository at this point in the history
fix deleting items with broken relation in languageindependent field
  • Loading branch information
pbauer authored Aug 18, 2021
2 parents 818d3c5 + ebf2c38 commit 1cf5297
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions news/390.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix deleting items with broken relation in languageindependent field
[pbauer]
17 changes: 12 additions & 5 deletions src/plone/app/multilingual/dx/cloner.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ def has_independent_fields(self):
return False

def copy_relation(self, relation_value, target_language):
if not relation_value or relation_value.isBroken():
return

obj = relation_value.to_object
intids = getUtility(IIntIds)
translation = ITranslationManager(obj).get_translation(target_language)
Expand All @@ -62,20 +65,24 @@ def copy_fields(self, translation):

target_language = queryAdapter(translation, ILanguage).get_language()

def relation_copier(rel, lang=target_language, fun=self.copy_relation):
return fun(rel, lang)

for schema in iterSchemata(self.context):
for field_name in schema:
if ILanguageIndependentField.providedBy(schema[field_name]):
value = getattr(schema(self.context), field_name, _marker)

if value == _marker:
continue
elif IRelationValue.providedBy(value):
value = self.copy_relation(value, target_language)
elif IRelationList.providedBy(schema[field_name]):
value = list(map(relation_copier, value or []))
if not value:
value = []
else:
new_value = []
for relation in value:
copied_relation = self.copy_relation(relation, target_language)
if copied_relation:
new_value.append(copied_relation)
value = new_value

doomed = True
setattr(schema(translation),
Expand Down

0 comments on commit 1cf5297

Please sign in to comment.