Insert to mysql, can find data inserted in mysql but the method returns with Err(RecordNotFound("Failed to find inserted item")).
westYY123 opened this issue · 1 comments
westYY123 commented
Description
hi, I am developing the backend of an app with axum and sea-orm, so there is a route to register a user, and insert the user to databse, i am using mysql as my database, but any time i call this route, it returns with Err(RecordNotFound("Failed to find inserted item")), however, i can find data in my database.
Steps to Reproduce
the below is the router
pub async fn register(
State(app_data): State<Arc<AppData>>,
Json(req): Json<RegisterRequest>,
) -> AppResult<Json<RegisterResponse>> {
let res = user::insert_user(&app_data.mysql_client, req.username, req.password).await;
println!("{res:?}");
// .map_err(|_| AppError::InternalError)?;
Ok(Json(RegisterResponse { success: true }))
}
the below is the database operator, the res is Err(RecordNotFound("Failed to find inserted item")).
pub async fn insert_user(
conn: &DatabaseConnection,
username: String,
password: String,
) -> AppResult<Model> {
let existing_user = get_user(conn, &username)
.await
.map_err(|_| AppError::InternalError)?;
match existing_user {
Some(_) => Err(AppError::ExistingSameUsername),
None => {
let user = ActiveModel {
id: Set("test-id".to_string()),
username: Set(username),
password: Set(password),
};
let res = user.insert(conn).await;
println!("{res:?}");
res.map_err(|_| AppError::InternalError)
}
}
}
Expected Behavior
returns the Model.
Actual Behavior
returns err Err(RecordNotFound("Failed to find inserted item"))
Reproduces How Often
every time
Workarounds
Reproducible Example
Versions
sqlx = "0.7"
sea-orm = { version = "0.12", features = [
"sqlx-mysql",
"runtime-tokio-native-tls",
"macros",
"with-chrono",
] }