Fix: Square brackets made the expression a list and the next generator would not work on it

This commit is contained in:
Amritanshu Agrawal 2022-06-21 08:44:00 +05:30
parent 61bb62475b
commit e37d160b7c
3 changed files with 3 additions and 3 deletions

View File

@ -298,7 +298,7 @@ def modifier_category_blank(date_: date, db: Session) -> schemas.ModifierCategor
def add_products(modifier_category: ModifierCategory, menu_categories: list[schemas.MenuCategoryLink], db: Session):
for mc in menu_categories:
for p in mc.products:
old = next([x for x in modifier_category.products if x.id == p.id_], None)
old = next((x for x in modifier_category.products if x.id == p.id_), None)
if p.enabled and old is None:
product_object = db.execute(select(Product).where(Product.id == p.id_)).scalar_one()
modifier_category.products.append(product_object)

View File

@ -141,7 +141,7 @@ def role_blank(db: Session) -> schemas.RoleBlank:
def add_permissions(role: Role, permissions: list[schemas.PermissionItem], db: Session):
for permission in permissions:
gp = next([p for p in role.permissions if p.id == permission.id_], None)
gp = next((p for p in role.permissions if p.id == permission.id_), None)
if permission.enabled and gp is None:
role.permissions.append(db.execute(select(Permission).where(Permission.id == permission.id_)).scalar_one())
elif not permission.enabled and gp:

View File

@ -93,7 +93,7 @@ def update_route(
def add_roles(user: User, roles: list[schemas.RoleItem], db: Session):
for role in roles:
ug = next([g for g in user.roles if g.id == role.id_], None)
ug = next((g for g in user.roles if g.id == role.id_), None)
if role.enabled and ug is None:
user.roles.append(db.execute(select(Role).where(Role.id == role.id_)).scalar_one())
elif not role.enabled and ug: