[Bug] ic_stable_structures data is not load when upgrade canister

Here is my code

thread_local! {
    static MEMORY_MANAGER: RefCell<MemoryManager<DefaultMemoryImpl>> = RefCell::new(MemoryManager::init(DefaultMemoryImpl::default()));

    static USER_STORE: RefCell<StableBTreeMap<
        String,
        User,
        Memory
    >> = RefCell::new(
        StableBTreeMap::init(
            MEMORY_MANAGER.with_borrow(|m| m.get(USER_MEMORY_ID)),
        )
    );
}

When I made an upgrade the data in USER_STORE is gone. It only work when I put this code in the post_upgrade

 USER_STORE.with(|t| {
            *t.borrow_mut() = StableBTreeMap::init(
                MEMORY_MANAGER.with_borrow(|m| m.get(USER_MEMORY_ID)),
            );
 });

Can you please take a look at this thread?

Review the notes here to see if you are not overwriting stable structures. Please let us know if this helps!

2 Likes

Yes, Iā€™m using stable_restore with my legacy code, I change it to memory management so it fixed

1 Like