Skip to content

Commit c2be42d

Browse files
committed
cleanup
1 parent b51b95e commit c2be42d

File tree

1 file changed

+17
-12
lines changed
  • services/web/server/src/simcore_service_webserver/products

1 file changed

+17
-12
lines changed

services/web/server/src/simcore_service_webserver/products/_repository.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@
5555
products.c.group_id,
5656
]
5757

58+
assert {column.name for column in _PRODUCTS_COLUMNS}.issubset( # nosec
59+
set(Product.model_fields)
60+
)
61+
62+
63+
def _to_domain(products_row: Row, payments: PaymentFieldsTuple) -> Product:
64+
return Product(
65+
**products_row._asdict(),
66+
is_payment_enabled=payments.enabled,
67+
credits_per_usd=payments.credits_per_usd,
68+
)
69+
5870

5971
async def _get_product_payment_fields(
6072
conn: AsyncConnection, product_name: ProductName
@@ -81,14 +93,6 @@ async def _get_product_payment_fields(
8193
)
8294

8395

84-
def _to_domain(row: Row, payments: PaymentFieldsTuple) -> Product:
85-
return Product(
86-
**row._asdict(),
87-
is_payment_enabled=payments.enabled,
88-
credits_per_usd=payments.credits_per_usd,
89-
)
90-
91-
9296
class ProductRepository(BaseRepositoryV2):
9397

9498
async def list_products(
@@ -130,7 +134,6 @@ async def get_product(
130134
query = sa.select(*_PRODUCTS_COLUMNS).where(products.c.name == product_name)
131135

132136
async with pass_or_acquire_connection(self.engine, connection) as conn:
133-
134137
result = await conn.execute(query)
135138
if row := result.one_or_none():
136139
payments = await _get_product_payment_fields(
@@ -157,9 +160,11 @@ async def get_product_stripe_info(
157160
self, product_name: str, connection: AsyncConnection | None = None
158161
) -> ProductStripeInfoGet:
159162
async with pass_or_acquire_connection(self.engine, connection) as conn:
160-
row = await get_product_latest_stripe_info(conn, product_name=product_name)
163+
stripe_price_id, stripe_tax_rate_id = await get_product_latest_stripe_info(
164+
conn, product_name=product_name
165+
)
161166
return ProductStripeInfoGet(
162-
stripe_price_id=row[0], stripe_tax_rate_id=row[1]
167+
stripe_price_id=stripe_price_id, stripe_tax_rate_id=stripe_tax_rate_id
163168
)
164169

165170
async def get_template_content(
@@ -211,8 +216,8 @@ async def auto_create_products_groups(
211216
connection: AsyncConnection | None = None,
212217
) -> dict[ProductName, GroupID]:
213218
product_groups_map: dict[ProductName, GroupID] = {}
214-
product_names = await self.list_products_names(connection)
215219

220+
product_names = await self.list_products_names(connection)
216221
for product_name in product_names:
217222
# NOTE: transaction is per product. fail-fast!
218223
async with transaction_context(self.engine, connection) as conn:

0 commit comments

Comments
 (0)