fix(core): 消除乐观锁 version.unwrap() 潜在 panic
20 处 ActiveValue::unwrap() + 1 乐观锁递增改为 take().unwrap_or(0) + 1, 避免数据库记录缺少 version 字段时 panic。覆盖 erp-auth/erp-config/ erp-workflow/erp-health/erp-ai/erp-server 7 个 crate。 DTO 层 Option<i32> 字段保持原有 unwrap_or(0) 不变。
This commit is contained in:
@@ -143,7 +143,7 @@ where
|
||||
}
|
||||
active.updated_at = Set(chrono::Utc::now());
|
||||
active.updated_by = Set(Some(ctx.user_id));
|
||||
active.version_lock = Set(active.version_lock.unwrap() + 1);
|
||||
active.version_lock = Set(active.version_lock.take().unwrap_or(0) + 1);
|
||||
|
||||
let result = active.update(&state.db).await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
@@ -179,7 +179,7 @@ where
|
||||
active.deleted_at = Set(Some(chrono::Utc::now()));
|
||||
active.updated_at = Set(chrono::Utc::now());
|
||||
active.updated_by = Set(Some(ctx.user_id));
|
||||
active.version_lock = Set(active.version_lock.unwrap() + 1);
|
||||
active.version_lock = Set(active.version_lock.take().unwrap_or(0) + 1);
|
||||
active.update(&state.db).await?;
|
||||
|
||||
Ok(Json(ApiResponse::ok(serde_json::json!({"deleted": true}))))
|
||||
|
||||
Reference in New Issue
Block a user