Skip to content

Commit

Permalink
fix: parent group update fixed; logger messages updated
Browse files Browse the repository at this point in the history
  • Loading branch information
nenenko committed Jul 16, 2024
1 parent 24c9ee8 commit e1f503f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
13 changes: 6 additions & 7 deletions scripts/user_group_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,7 @@ def _get_gd_user_groups(self) -> list[CatalogUserGroup]:
def _is_changed(group: TargetUserGroup, existing_group: CatalogUserGroup) -> bool:
"""Checks if user group has some changes and needs to be updated."""
group.parent_user_groups.sort()
parents_changed = (
group.parent_user_groups != existing_group.get_parents
)
parents_changed = group.parent_user_groups != existing_group.get_parents
name_changed = group.user_group_name != existing_group.name
return parents_changed or name_changed

Expand All @@ -247,7 +245,10 @@ def _create_or_update_user_group(
self.sdk.catalog_user.create_or_update_user_group(catalog_user_group)
logger.info(f"Succeeded to {action} user group {group_id}")
except Exception as e:
message = e.args[0] if e.args else eval(e.body)["detail"]
if hasattr(e, "body") and e.body:
message = eval(e.body).get("detail", e)
else:
message = e.args[0] if e.args else str(e)
logger.error(f"Failed to {action} user group {group_id}: {message}")

def _create_missing_user_groups(self, group_ids_to_create) -> None:
Expand Down Expand Up @@ -282,9 +283,7 @@ def _update_existing_user_groups(self, group_ids_to_update) -> None:
for group in groups_to_update:
existing_group = existing_groups[group.user_group_id]
if self._is_changed(group, existing_group):
logger.info(
f"Updating user group {group.user_group_id}..."
)
logger.info(f"Updating user group {group.user_group_id}...")
self._create_or_update_user_group(
group.user_group_id,
group.user_group_name,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,13 +408,13 @@ def test_load_user_data_filters():
user_data_filters_expected = {
"userDataFilters": [
{
"id": "datafilter2",
"id": "datafilter4",
"maql": '{label/campaign_channels.category} = "1"',
"title": "Status filter",
"user": {"id": "5c867a8a-12af-45bf-8d85-c7d16bedebd1", "type": "user"},
},
{
"id": "datafilter4",
"id": "datafilter2",
"maql": '{label/campaign_channels.category} = "1"',
"title": "Status filter",
"user": {"id": "5c867a8a-12af-45bf-8d85-c7d16bedebd1", "type": "user"},
Expand Down

0 comments on commit e1f503f

Please sign in to comment.