From f724e9763ff674f89db01d11a03cb2ae0d5f31ac Mon Sep 17 00:00:00 2001 From: Priec Date: Mon, 22 Jun 2026 16:56:14 +0200 Subject: [PATCH] upload picture now working well --- src/controllers/admin_products.rs | 2 +- src/models/product_images.rs | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/controllers/admin_products.rs b/src/controllers/admin_products.rs index 3ff0ee7..af583db 100644 --- a/src/controllers/admin_products.rs +++ b/src/controllers/admin_products.rs @@ -526,7 +526,7 @@ async fn update( if let Some(data) = form.image { let filename = store_image(&ctx, data).await?; - let next_position = product_images::count_for(&ctx, id).await?; + let next_position = product_images::count_for(&txn, id).await?; product_images::ActiveModel { product_id: Set(id), image_id: Set(filename), diff --git a/src/models/product_images.rs b/src/models/product_images.rs index e701593..a7d5fa2 100644 --- a/src/models/product_images.rs +++ b/src/models/product_images.rs @@ -38,10 +38,14 @@ pub async fn first_for(ctx: &AppContext, product_id: i32) -> Result Result { +/// +/// Takes a connection rather than the `AppContext` so it can run on an open +/// transaction; calling it on `ctx.db` while a transaction holds the pool's only +/// connection would deadlock the pool. +pub async fn count_for(db: &C, product_id: i32) -> Result { use sea_orm::PaginatorTrait; Ok(Entity::find() .filter(Column::ProductId.eq(product_id)) - .count(&ctx.db) + .count(db) .await? as i32) }