Skip to content

Commit

Permalink
fix(patch): fix duplication error in patch "M2-6879" for arbittrary D…
Browse files Browse the repository at this point in the history
…Bs (M2-7055) (#1415)
  • Loading branch information
vshvechko authored Jun 17, 2024
1 parent bf63307 commit f6295bc
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ async def get_answers_applets_respondents(


async def get_missing_applet_respondent(
session: AsyncSession, owner_id: uuid.UUID, arbitrary_applet_respondents: set[tuple[uuid.UUID, uuid.UUID]]
session: AsyncSession, applet_ids: list[uuid.UUID], arbitrary_applet_respondents: set[tuple[uuid.UUID, uuid.UUID]]
) -> list[tuple[uuid.UUID, uuid.UUID]]:
query: Query = select(UserAppletAccessSchema.user_id, UserAppletAccessSchema.applet_id)
query = query.where(UserAppletAccessSchema.owner_id == owner_id, UserAppletAccessSchema.role == Role.RESPONDENT)
query = query.where(
UserAppletAccessSchema.applet_id.in_(applet_ids), UserAppletAccessSchema.role == Role.RESPONDENT
)
db_result = await session.execute(query)
roles_users_applets = db_result.all()
return list(arbitrary_applet_respondents - set(roles_users_applets))
Expand All @@ -93,7 +95,12 @@ async def find_and_create_missing_roles_arbitrary(
roles = []
for offset in range(0, count, limit):
arbitrary_applet_respondents = await get_answers_applets_respondents(arbitrary_session, limit, offset)
missing_users_applets = await get_missing_applet_respondent(session, owner_id, arbitrary_applet_respondents)

applet_ids = {x[1] for x in arbitrary_applet_respondents}

missing_users_applets = await get_missing_applet_respondent(
session, list(applet_ids), arbitrary_applet_respondents
)
for user_id, applet_id in missing_users_applets:
schema = UserAppletAccessSchema(
user_id=user_id,
Expand Down Expand Up @@ -137,10 +144,10 @@ async def main(session: AsyncSession, *args, **kwargs):
async with session_maker() as arb_session:
try:
await find_and_create_missing_roles_arbitrary(session, arb_session, workspace.user_id)
await arb_session.commit()
await session.commit()
print(f"Processing workspace#{i + 1} {workspace.id} " f"finished")
except Exception:
await arb_session.rollback()
await session.rollback()
print(f"[bold red]Error: Workspace#{i + 1} {workspace.id} processing error[/bold red]")
raise
except asyncio.TimeoutError:
Expand Down

0 comments on commit f6295bc

Please sign in to comment.