Skip to content

Commit 0568393

Browse files
authored
fix: Don't change ConfiguredAddr when adding a transport (#6804)
Before this PR, ConfiguredAddr (which will be used to store the primary transport) would have been changed when adding a new transport. Doesn't matter yet because it's not possible yet to have multiple transports. But I wanted to fix this bug already so that I'm not suprised by it later.
1 parent 7ec7329 commit 0568393

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/login_param.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -809,20 +809,14 @@ impl ConfiguredLoginParam {
809809
entered_param: &EnteredLoginParam,
810810
) -> Result<()> {
811811
let addr = addr_normalize(&self.addr);
812+
let provider_id = self.provider.map(|provider| provider.id);
812813
let configured_addr = context.get_config(Config::ConfiguredAddr).await?;
813-
if let Some(configured_addr) = configured_addr {
814+
if let Some(configured_addr) = &configured_addr {
814815
ensure!(
815-
addr_cmp(&configured_addr, &addr,),
816+
addr_cmp(configured_addr, &addr),
816817
"Adding a second transport is not supported right now."
817818
);
818819
}
819-
context
820-
.sql
821-
.set_raw_config(
822-
Config::ConfiguredProvider.as_ref(),
823-
self.provider.map(|provider| provider.id),
824-
)
825-
.await?;
826820
context
827821
.sql
828822
.execute(
@@ -837,10 +831,17 @@ impl ConfiguredLoginParam {
837831
),
838832
)
839833
.await?;
840-
context
841-
.sql
842-
.set_raw_config(Config::ConfiguredAddr.as_ref(), Some(&addr))
843-
.await?;
834+
if configured_addr.is_none() {
835+
// If there is no transport yet, set the new transport as the primary one
836+
context
837+
.sql
838+
.set_raw_config(Config::ConfiguredProvider.as_ref(), provider_id)
839+
.await?;
840+
context
841+
.sql
842+
.set_raw_config(Config::ConfiguredAddr.as_ref(), Some(&addr))
843+
.await?;
844+
}
844845
Ok(())
845846
}
846847

0 commit comments

Comments
 (0)