Skip to content

Commit

Permalink
Fix sync - updating source string from VCS not working
Browse files Browse the repository at this point in the history
  • Loading branch information
haodave committed Jan 3, 2025
1 parent 42421cd commit 4dd575d
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions pontoon/sync/core/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from collections import defaultdict
from datetime import datetime
from os.path import exists, isfile, join, relpath, splitext
from typing import Optional

from moz.l10n.paths import L10nConfigPaths, L10nDiscoverPaths

Expand Down Expand Up @@ -162,23 +163,22 @@ def update_resources(
obsolete_entities, ["obsolete", "date_obsoleted"]
)

mod_count = Entity.objects.bulk_update(
(
ent
for key, ent in next_entities.items()
if key in prev_entities.keys() & next_entities.keys()
and not entities_same(ent, prev_entities[key])
),
[
"string",
"string_plural",
"comment",
"source",
"group_comment",
"resource_comment",
"context",
],
)
mod_fields = [
"string",
"string_plural",
"comment",
"source",
"group_comment",
"resource_comment",
]
mod_entities = [
ent
for key, next_ent in next_entities.items()
if key in prev_entities.keys() & next_entities.keys()
and (ent := entity_update(prev_entities[key], next_ent, mod_fields))
]
mod_count = len(mod_entities)
Entity.objects.bulk_update(mod_entities, mod_fields)

# FIXME: Entity order should be updated on insertion
# https://github.com/mozilla/pontoon/issues/2115
Expand Down Expand Up @@ -333,6 +333,18 @@ def entities_same(a: Entity, b: Entity) -> bool:
)


def entity_update(
current: Entity, update_from: Entity, fields: list[str]
) -> Optional[Entity]:
updated = False
for field in fields:
if getattr(current, field) != getattr(update_from, field):
setattr(current, field, getattr(update_from, field))
updated = True

return current if updated else None


def get_db_path(paths: L10nConfigPaths | L10nDiscoverPaths, file_path: str) -> str:
rel_path = relpath(file_path, paths.ref_root)
return (
Expand Down

0 comments on commit 4dd575d

Please sign in to comment.