@@ -47,7 +47,7 @@ impl<'c> PgCompatSessionRepository<'c> {
4747
4848struct CompatSessionLookup {
4949 compat_session_id : Uuid ,
50- device_id : String ,
50+ device_id : Option < String > ,
5151 user_id : Uuid ,
5252 user_session_id : Option < Uuid > ,
5353 created_at : DateTime < Utc > ,
@@ -63,12 +63,16 @@ impl TryFrom<CompatSessionLookup> for CompatSession {
6363
6464 fn try_from ( value : CompatSessionLookup ) -> Result < Self , Self :: Error > {
6565 let id = value. compat_session_id . into ( ) ;
66- let device = Device :: try_from ( value. device_id ) . map_err ( |e| {
67- DatabaseInconsistencyError :: on ( "compat_sessions" )
68- . column ( "device_id" )
69- . row ( id)
70- . source ( e)
71- } ) ?;
66+ let device = value
67+ . device_id
68+ . map ( Device :: try_from)
69+ . transpose ( )
70+ . map_err ( |e| {
71+ DatabaseInconsistencyError :: on ( "compat_sessions" )
72+ . column ( "device_id" )
73+ . row ( id)
74+ . source ( e)
75+ } ) ?;
7276
7377 let state = match value. finished_at {
7478 None => CompatSessionState :: Valid ,
@@ -96,7 +100,7 @@ impl TryFrom<CompatSessionLookup> for CompatSession {
96100#[ enum_def]
97101struct CompatSessionAndSsoLoginLookup {
98102 compat_session_id : Uuid ,
99- device_id : String ,
103+ device_id : Option < String > ,
100104 user_id : Uuid ,
101105 user_session_id : Option < Uuid > ,
102106 created_at : DateTime < Utc > ,
@@ -118,12 +122,16 @@ impl TryFrom<CompatSessionAndSsoLoginLookup> for (CompatSession, Option<CompatSs
118122
119123 fn try_from ( value : CompatSessionAndSsoLoginLookup ) -> Result < Self , Self :: Error > {
120124 let id = value. compat_session_id . into ( ) ;
121- let device = Device :: try_from ( value. device_id ) . map_err ( |e| {
122- DatabaseInconsistencyError :: on ( "compat_sessions" )
123- . column ( "device_id" )
124- . row ( id)
125- . source ( e)
126- } ) ?;
125+ let device = value
126+ . device_id
127+ . map ( Device :: try_from)
128+ . transpose ( )
129+ . map_err ( |e| {
130+ DatabaseInconsistencyError :: on ( "compat_sessions" )
131+ . column ( "device_id" )
132+ . row ( id)
133+ . source ( e)
134+ } ) ?;
127135
128136 let state = match value. finished_at {
129137 None => CompatSessionState :: Valid ,
@@ -347,7 +355,7 @@ impl CompatSessionRepository for PgCompatSessionRepository<'_> {
347355 id,
348356 state : CompatSessionState :: default ( ) ,
349357 user_id : user. id ,
350- device,
358+ device : Some ( device ) ,
351359 user_session_id : browser_session. map ( |s| s. id ) ,
352360 created_at,
353361 is_synapse_admin,
@@ -364,7 +372,7 @@ impl CompatSessionRepository for PgCompatSessionRepository<'_> {
364372 db. query. text,
365373 %compat_session. id,
366374 user. id = %compat_session. user_id,
367- compat_session. device. id = compat_session. device. as_str ( ) ,
375+ compat_session. device. id = compat_session. device. as_ref ( ) . map ( mas_data_model :: Device :: as_str ) ,
368376 ) ,
369377 err,
370378 ) ]
0 commit comments