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:
@@ -137,7 +137,7 @@ impl AuthService {
|
||||
let mut user_active: user::ActiveModel = user_model.clone().into();
|
||||
user_active.last_login_at = Set(Some(Utc::now()));
|
||||
user_active.updated_at = Set(Utc::now());
|
||||
user_active.version = Set(user_active.version.unwrap() + 1);
|
||||
user_active.version = Set(user_active.version.take().unwrap_or(0) + 1);
|
||||
user_active
|
||||
.update(db)
|
||||
.await
|
||||
|
||||
@@ -299,7 +299,7 @@ impl RoleService {
|
||||
active.deleted_at = Set(Some(now));
|
||||
active.updated_at = Set(now);
|
||||
active.updated_by = Set(operator_id);
|
||||
active.version = Set(active.version.unwrap() + 1);
|
||||
active.version = Set(active.version.take().unwrap_or(0) + 1);
|
||||
active
|
||||
.update(db)
|
||||
.await
|
||||
|
||||
@@ -168,7 +168,7 @@ impl TokenService {
|
||||
let mut active: user_token::ActiveModel = token_row.into();
|
||||
active.revoked_at = Set(Some(Utc::now()));
|
||||
active.updated_at = Set(Utc::now());
|
||||
active.version = Set(active.version.unwrap() + 1);
|
||||
active.version = Set(active.version.take().unwrap_or(0) + 1);
|
||||
active
|
||||
.update(db)
|
||||
.await
|
||||
@@ -238,7 +238,7 @@ impl TokenService {
|
||||
let mut active: user_token::ActiveModel = token.into();
|
||||
active.revoked_at = Set(Some(now));
|
||||
active.updated_at = Set(now);
|
||||
active.version = Set(active.version.unwrap() + 1);
|
||||
active.version = Set(active.version.take().unwrap_or(0) + 1);
|
||||
active
|
||||
.update(db)
|
||||
.await
|
||||
|
||||
Reference in New Issue
Block a user