Skip to content

Commit

Permalink
🐛 Fix query loading navigation arrangements
Browse files Browse the repository at this point in the history
A somewhat legacy bug is the root cause. Very old user accounts might not have their `user_id` fk set on their associated `user_preferences`. The root is fixed, but the error would crop up for those old accounts. Ideally a future migration will remove the issue entirely, but this will fix the immediate bug as a start
  • Loading branch information
aaronleopold committed Apr 20, 2024
1 parent 724f7e0 commit b6e312d
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions apps/server/src/routers/api/v1/user.rs
Expand Up @@ -637,12 +637,14 @@ async fn get_navigation_arrangement(

let user_preferences = db
.user_preferences()
.find_unique(user_preferences::user_id::equals(user.id.clone()))
.find_first(vec![user_preferences::user::is(vec![user::id::equals(
user.id.clone(),
)])])
.exec()
.await?
.ok_or(APIError::NotFound(format!(
"User preferences with id {} not found",
user.id
"User preferences for {} not found",
user.username
)))?;
let user_preferences = UserPreferences::from(user_preferences);

Expand Down Expand Up @@ -672,12 +674,16 @@ async fn update_navigation_arrangement(

let user_preferences = db
.user_preferences()
.find_unique(user_preferences::user_id::equals(user.id.clone()))
// TODO: Really old accounts potentially have users with preferences missing a `user_id`
// assignment. This should be more properly fixed in the future, e.g. by a migration.
.find_first(vec![user_preferences::user::is(vec![user::id::equals(
user.id.clone(),
)])])
.exec()
.await?
.ok_or(APIError::NotFound(format!(
"User preferences with id {} not found",
user.id
"User preferences for {} not found",
user.username
)))?;
let user_preferences = UserPreferences::from(user_preferences);

Expand Down

0 comments on commit b6e312d

Please sign in to comment.