diff --git a/src/scribe/services/backup.py b/src/scribe/services/backup.py index 6491975..50e9f82 100644 --- a/src/scribe/services/backup.py +++ b/src/scribe/services/backup.py @@ -767,14 +767,6 @@ async def export_user_backup(user_id: int) -> dict: usage_events = (await session.execute( select(NoteUsageEvent).where(NoteUsageEvent.note_id.in_(note_ids)) )).scalars().all() if note_ids else [] - # Scoped through the RULE, not the event's user_id — the same call - # rule_versions makes one block up. user_id here is whoever the arm - # fired for, so filtering on it would carry this user's surfacings of - # someone ELSE's rule and drop the ones fired for someone else on - # theirs: the opposite of a per-user export. - rule_usage_events = (await session.execute( - select(RuleUsageEvent).where(RuleUsageEvent.rule_id.in_(_rule_ids)) - )).scalars().all() if _rule_ids else [] repo_bindings = (await session.execute( select(RepoBinding).where(RepoBinding.user_id == user_id) )).scalars().all() @@ -826,6 +818,14 @@ async def export_user_backup(user_id: int) -> dict: select(RuleVersion).where(RuleVersion.rule_id.in_(_rule_ids)) .order_by(RuleVersion.rule_id, RuleVersion.id) )).scalars().all() if _rule_ids else [] + # Scoped through the RULE for the same reason the versions above are, + # and it is worth restating because the column that looks right is + # wrong: `user_id` here is whoever the arm fired FOR, not who owns the + # rule. Filtering on it would carry this user's surfacings of someone + # ELSE's rule and drop the ones fired for someone else on theirs. + rule_usage_events = (await session.execute( + select(RuleUsageEvent).where(RuleUsageEvent.rule_id.in_(_rule_ids)) + )).scalars().all() if _rule_ids else [] rule_relations = (await session.execute( select(RuleRelation).where( RuleRelation.from_rule_id.in_(_rule_ids),