EnxDev commented on code in PR #42472:
URL: https://github.com/apache/superset/pull/42472#discussion_r3656986102
##########
superset/subjects/utils.py:
##########
@@ -176,6 +241,26 @@ def get_or_create_role_subject(role_id: int) -> Subject |
None:
return get_role_subject(role_id)
+def subjects_from_groups(groups: list[Group | int]) -> list[Subject]:
+ """Convert a list of Group objects or group IDs to GROUP-type Subjects.
+
+ Mirrors :func:`subjects_from_roles`, but resolves the whole list in one
+ query rather than one per group. Silently skips groups without a matching
+ Subject row.
Review Comment:
Fixed both halves. The non-flush path (get_user_group_subjects, used by the
create/import flows) now backfills missing group Subjects on demand via a new
get_or_create_group_subject (mirroring get_or_create_role_subject). The
flush-event path (subjects_from_groups → copy_dashboard, where an on-demand
sync's flush is unsafe) can't backfill, so get_default_viewers_for_groups is
now all-or-nothing: if any group fails to resolve it returns [] rather than a
partial list — keeping the datasource-access fallback intact instead of
switching it off and locking the unsynced group's members out. You're right
that unsynced groups are a real state (the sync-subjects CLI, no backfill
migration), so I dropped my earlier "not reached in practice" assumption. Tests
cover both paths, including get_default_viewers_for_groups([g1, g2]) == [] when
g2 lacks a Subject.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]