@mcc it looks like it's because you're left joining the users table, which makes those columns nullable and not necessarily present on the output table. there are diagnostics in your unmodified code for e.g. "cannot select `avatar` from `fedivote_common::db::sessions::table`", "Note: `avatar` is no valid selection for `fedivote_common::db::sessions::table`", etc.

it doesn't seem like there's a way to very easily select an `Option<User>` either, not sure why it can't helpfully cascade nullability to each of the selected fields from that table... but it doesn't seem to do that. you can write this by specifically selecting all the fields you care about and then just use those at least

@mcc
```patch
<+>UTF-8
===================================================================
diff --git a/server/src/session.rs b/server/src/session.rs
--- a/server/src/session.rs (revision d8ee9d53c2fd7a01e6e2fbdddc971b7200480386)
+++ b/server/src/session.rs (date 1760236973979)
@@ -53,32 +53,38 @@
}

// Can impact db
-pub async fn get_session(cookies: &CookieJar<'_>, mut conn: Connection<Db>) -> Option<CurrentLogin> {
- if let Some(token) = get_session_token(cookies) {
- use rocket_db_pools::diesel::prelude::*;
- let filter = db::sessions::table
- .left_join(db::users::table)
- .filter(db::sessions::id.eq(token as i64));
+pub async fn get_session(
+ cookies: &CookieJar<'_>,
+ mut conn: Connection<Db>,
+) -> Option<CurrentLogin> {
+ let token = get_session_token(cookies)?;
+ use rocket_db_pools::diesel::prelude::*;
+ let filter = db::sessions::table
+ .left_join(db::users::table)
+ .filter(db::sessions::id.eq(token as i64));

- let user_row = filter.select(db::User::as_select())
- .load(&mut conn)
- .await;
+ let user_row = filter
+ .select(
+ (
+ db::users::dsl::username,
+ db::users::dsl::server,
+ db::users::dsl::avatar,
+ )
+ .nullable(),
+ )
+ .load(&mut conn)
+ .await;

- match user_row {
- Ok(v) => {
- let v = v[0];
- let () = v;
- Some(CurrentLogin {
- username: v.username,
- server: v.server,
- avatar: v.avatar
- })
- }
- e => None // TODO: Report? Clear cookie? Do anything?
- }
- } else {
- None
- }
+ // TODO: handle error here instead?
+ for row in user_row.ok()? {
+ let (username, server, avatar) = row?;
+ return Some(CurrentLogin {
+ username,
+ server,
+ avatar,
+ });
+ }
+ None
}

// Impacts db
```

0

If you have a fediverse account, you can quote this note from your own instance. Search https://hachyderm.io/users/widr/statuses/115358896188019566 on your instance and quote it. (Note that quoting is not supported in Mastodon.)