Skip to content

Commit

Permalink
Formats: Fix handling of obsolete units with same content as valid ones
Browse files Browse the repository at this point in the history
We should not use the obsolete units in the lookups, otherwise we might
end up updating the obsolete unit instead of current one.

Signed-off-by: Michal Čihař <michal@cihar.com>
  • Loading branch information
nijel committed Nov 13, 2019
1 parent 6b7c729 commit bf2863c
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
13 changes: 7 additions & 6 deletions weblate/formats/base.py
Expand Up @@ -144,10 +144,6 @@ def is_fuzzy(self, fallback=False):
"""Check whether unit needs edit."""
return fallback

def is_obsolete(self):
"""Check whether unit is marked as obsolete in backend."""
return False

def has_content(self):
"""Check whether unit has content."""
return True
Expand Down Expand Up @@ -319,15 +315,20 @@ def save(self):
"""Save underlaying store to disk."""
raise NotImplementedError()

@property
def all_store_units(self):
"""Wrapper for all store units for possible filtering."""
return self.store.units

@cached_property
def mono_units(self):
return [self.unit_class(self, None, unit) for unit in self.store.units]
return [self.unit_class(self, None, unit) for unit in self.all_store_units]

@cached_property
def all_units(self):
"""List of all units."""
if not self.has_template:
return [self.unit_class(self, unit) for unit in self.store.units]
return [self.unit_class(self, unit) for unit in self.all_store_units]
return [
self.unit_class(
self, self.find_unit_mono(unit.context), unit.template
Expand Down
9 changes: 5 additions & 4 deletions weblate/formats/ttkit.py
Expand Up @@ -116,10 +116,6 @@ def is_fuzzy(self, fallback=False):
return self.unit.isfuzzy()
return fallback

def is_obsolete(self):
"""Check whether unit is marked as obsolete in backend."""
return self.mainunit.isobsolete()

def has_content(self):
"""Check whether unit has content."""
return (
Expand Down Expand Up @@ -356,6 +352,11 @@ def is_valid_base_for_new(cls, base, monolingual):
report_error(error, prefix='File parse error')
return False

@property
def all_store_units(self):
"""Wrapper for all store unit filtering out obsolete."""
return (unit for unit in self.store.units if not unit.isobsolete())


class PropertiesUnit(KeyValueUnit):
"""Wrapper for properties based units."""
Expand Down
2 changes: 1 addition & 1 deletion weblate/trans/models/translation.py
Expand Up @@ -524,7 +524,7 @@ def update_units(self, author_name, author_id):
unit.pending = False

# Bail out if we have not found anything
if pounit is None or pounit.is_obsolete():
if pounit is None:
self.log_error('disappeared string: %s', unit)
unit.save(update_fields=['pending'], same_content=True)
continue
Expand Down
Binary file modified weblate/trans/tests/data/test-base-repo.git.tar
Binary file not shown.
Binary file modified weblate/trans/tests/data/test-base-repo.hg.tar
Binary file not shown.
Binary file modified weblate/trans/tests/data/test-base-repo.svn.tar
Binary file not shown.

0 comments on commit bf2863c

Please sign in to comment.