Skip to content

Commit

Permalink
Don't rely on the string representations of objects to keep track of …
Browse files Browse the repository at this point in the history
…the parameters used for the diff
  • Loading branch information
kemar committed Jan 3, 2025
1 parent 7c294c0 commit 92379fc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
44 changes: 34 additions & 10 deletions iaso/models/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,15 @@ def clean_data_source_versions(self) -> None:
def create_json_diff(
self,
logger_to_use: logging.Logger = None,
source_version_to_update_validation_status: typing.Union[str, None] = None,
source_version_to_update_top_org_unit: typing.Union[int, "OrgUnit", None] = None,
source_version_to_update_org_unit_types: typing.Optional[list["OrgUnitType"]] = None,
source_version_to_compare_with_validation_status: typing.Union[str, None] = None,
source_version_to_compare_with_top_org_unit: typing.Union[int, "OrgUnit", None] = None,
source_version_to_compare_with_org_unit_types: typing.Optional[list["OrgUnitType"]] = None,
ignore_groups: typing.Optional[bool] = False,
show_deleted_org_units: typing.Optional[bool] = False,
field_names: typing.Optional[list[str]] = None,
source_version_to_update_validation_status: str = None,
source_version_to_update_top_org_unit: "OrgUnit" = None,
source_version_to_update_org_unit_types: list["OrgUnitType"] = None,
source_version_to_compare_with_validation_status: str = None,
source_version_to_compare_with_top_org_unit: "OrgUnit" = None,
source_version_to_compare_with_org_unit_types: list["OrgUnitType"] = None,
ignore_groups: bool = False,
show_deleted_org_units: bool = False,
field_names: list[str] = None,
) -> None:
# Prevent a circular import.
from iaso.diffing import Differ, diffs_to_json
Expand Down Expand Up @@ -307,10 +307,34 @@ def create_json_diff(
if diff.status in count_status:
count_status[diff.status] += 1

# Keep track of the parameters used for the diff.
differ_config = {
# Version to update.
"version": self.source_version_to_update.pk,
"validation_status": source_version_to_update_validation_status,
"top_org_unit": source_version_to_update_top_org_unit.pk if source_version_to_update_top_org_unit else None,
"org_unit_types": [out.pk for out in source_version_to_update_org_unit_types]
if source_version_to_update_org_unit_types
else None,
# Version to compare with.
"version_ref": self.source_version_to_compare_with.pk,
"validation_status_ref": source_version_to_compare_with_validation_status,
"top_org_unit_ref": source_version_to_compare_with_top_org_unit.pk
if source_version_to_compare_with_top_org_unit
else None,
"org_unit_types_ref": [out.pk for out in source_version_to_compare_with_org_unit_types]
if source_version_to_compare_with_org_unit_types
else None,
# Options.
"ignore_groups": ignore_groups,
"show_deleted_org_units": show_deleted_org_units,
"field_names": field_names,
}

self.count_create = count_status["new"]
self.count_update = count_status["modified"]
self.json_diff = diffs_to_json(diffs)
self.diff_config = str(differ_params)
self.diff_config = str(differ_config)
self.save()

def synchronize_source_versions(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,14 @@ def test_create_json_diff(self):

expected_diff_config = (
"{"
f"'version': <SourceVersion: {str(self.source_version_to_update)}>, "
f"'version': {self.source_version_to_update.pk}, "
f"'validation_status': '{m.OrgUnit.VALIDATION_VALID}', "
"'top_org_unit': None, "
f"'org_unit_types': [<OrgUnitType: {str(self.org_unit_type_country)}>], "
f"'version_ref': <SourceVersion: {str(self.source_version_to_compare_with)}>, "
f"'org_unit_types': [{self.org_unit_type_country.pk}], "
f"'version_ref': {self.source_version_to_compare_with.pk}, "
f"'validation_status_ref': '{m.OrgUnit.VALIDATION_VALID}', "
"'top_org_unit_ref': None, "
f"'org_unit_types_ref': [<OrgUnitType: {str(self.org_unit_type_country)}>], "
f"'org_unit_types_ref': [{self.org_unit_type_country.pk}], "
"'ignore_groups': True, "
"'show_deleted_org_units': False, "
"'field_names': ['name']"
Expand Down

0 comments on commit 92379fc

Please sign in to comment.