Skip to content

fix: preserve existing identity data when loading by wallet#811

Draft
lklimek wants to merge 4 commits into
v1.0-devfrom
fix/identity-load-overwrite
Draft

fix: preserve existing identity data when loading by wallet#811
lklimek wants to merge 4 commits into
v1.0-devfrom
fix/identity-load-overwrite

Conversation

@lklimek

@lklimek lklimek commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Imagine you're a user who registered a DPNS name for your identity. You go to Load Identity > By Wallet to reload it (maybe after switching networks or reinstalling). Previously, the reload would silently delete your alias — the identity entry was completely overwritten with fresh-but-incomplete data. Now the app merges new data with existing records, preserving your alias and wallet associations.

Key changes

  • Alias derivation: load_identity_from_wallet.rs now derives the alias from the first DPNS name (same logic as load_identity.rs), instead of hardcoding alias: None
  • Database merge: insert_local_qualified_identity() changed from INSERT OR REPLACE (destructive overwrite) to INSERT ... ON CONFLICT DO UPDATE with COALESCE — preserves existing non-null alias, wallet, and wallet_index when the incoming value is NULL

What gets preserved vs updated

Field Behavior
data (identity blob) Always updated (fresh from Platform)
alias Kept if existing is non-null and incoming is null
wallet / wallet_index Kept if existing is non-null and incoming is null
identity_type Always updated
status Always updated
network Always updated

Test plan

  • cargo clippy --all-features --all-targets -- -D warnings passes
  • cargo test --all-features --workspace passes (511 tests)
  • Load an identity by ID with a DPNS name → alias is set
  • Reload the same identity via By Wallet → alias is preserved
  • Load a new identity via By Wallet with DPNS name → alias is derived from DPNS name
  • Load a new identity via By Wallet without DPNS name → alias remains NULL (no regression)

🤖 Co-authored by Claudius the Magnificent AI Agent

Two bugs caused identity data (especially alias) to be lost when
reloading an identity via Load Identity > By Wallet:

1. load_identity_from_wallet.rs hardcoded alias: None instead of
   deriving it from DPNS names (like load_identity.rs does). Now
   uses the first DPNS name as alias fallback.

2. insert_local_qualified_identity() used INSERT OR REPLACE which
   destroyed existing row data. Changed to INSERT ... ON CONFLICT
   with COALESCE to preserve existing non-null values (alias,
   wallet, wallet_index) when the incoming value is NULL.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f5277da8-e46e-4740-aded-ba7a64b2a43b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/identity-load-overwrite

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

lklimek and others added 3 commits April 1, 2026 14:58
…ment

Remove the if/else branch — one INSERT ... ON CONFLICT with COALESCE
handles both cases. When wallet_and_identity_id_info is None, wallet
and wallet_index are passed as NULL; COALESCE preserves any existing
non-null values in the row.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When BackendTestContext::init() panics (e.g. framework wallet
unfunded), tokio::sync::OnceCell retries on the next test. But the
orphaned SPV tasks from the panicked init keep running on the shared
tokio runtime, holding the data directory lock file. The retry then
fails with "Data directory locked".

Fix: stash the TaskManager's cancellation token in a static, and
install a global panic hook that cancels it. On retry, init() also
checks for and cancels any leftover token. This ensures SPV tasks
are stopped and the lock file is released before a fresh init.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…-overwrite

# Conflicts:
#	tests/backend-e2e/framework/harness.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant