### Is there an existing issue for this?

- [X] I have searched the existing issues

### Current behaviour

crash

### Expected behaviour

no crash

### Steps to reproduce

* Compile 79e8247ddb166f9b980f40249b7372a502402a4d
* Type `migratewallet`

### Relevant log output

```
wallet/scriptpubkeyman.cpp:1915: std::optional<MigrationData> wallet::LegacyScriptPubKeyMan::MigrateToDescriptor(): Assertion `IsMine(desc_spk) != ISMINE_NO' failed.
Aborted (core dumped)
```


### How did you obtain Bitcoin Core

Compiled from source

### What version of Bitcoin Core are you using?

current master

### Operating system and version

Linux

### Machine specifications

_No response_
}
    return nullptr;
}
stdoptional<bool> CWalIsInternalScriptPubKeyMan(ScriptPubKeyMan* spk_man) const
{
    // Legacy script pubkey man can't be either external or internal
    if (IsLegacy()) {
        return stdnullopt;
    }
    // only active ScriptPubKeyMan can be internal
    if (!GetActiveScriptPubKeyMans().count(spk_man)) {
        return stdnullopt;
    }
    const auto desc_spk_man = dynamic_cast<DescriptorScriptPubKeyMan*>(spk_man);
    if (!desc_spk_man) {
        throw stdruntime_error(stdstring(__func__) + " unexpected ScriptPubKeyMan type.");
    }
    LOCK(desc_spk_man->cs_desc_man);
    const auto& type = desc_spk_man->GetWalDescriptor().->GetOutputType();
    assert(type.has_value());
    return GetScriptPubKeyMan(*type, /* internal= sc_spk_man;
}
ScriptPubKeyMan* CWalAddWalDescriptor(WalDescriptor& desc, const FlatSigningProvider& signing_provider, const stdstring& label, bool internal)
{
    AssertLockHeld(cs_wal);
    if (!IsWalFlagSet(WALLET_FLAG_DESCRIPTORS)) {
        WalLogPrintf("Cannot add WalDescriptor to a non- wal\n");
        return nullptr;
    }
    auto spk_man = GetDescriptorScriptPubKeyMan(desc);