Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sync - updating source string from VCS not working #3506

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is context dropped?

],
)
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]:
Comment on lines +336 to +338
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is replacing the only use of entities_same() with a new function; we should not leave orphaned code lying around.

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
Loading