Why is impossible to reuse mapping key at mapping(uint256=>EnumberableSet.AddressSet)?

I've defined one state variable called data that has mapping(uint256=>EnumberableSet.AddressSet),
according to the requirements, I've deleted item like this.
delete data[0]

after delete, if I try to add one variable again with this key -> 0
data[0].add(msg.sender), no runtime error but happened nothing at variable data.
it maintain original values and don't save.
If faced on such trouble past time, could kindly teach me to solve this?
best.

You can't use delete with EnumerableSet. Please use data[0].clear().

clear function is not defined. I've just checked recent version also in openzeppelin repo.
so I've made myself wrapper just and working well.
thanks for your reply.
best.

Sorry I thought we had a clear function. I remember now that we don't.

You still shouldn't delete enumerable sets and maps. You should use a fresh instance at a fresh location if you need to reset it.

See the warning in the docs.

1 Like

Yeah so based on that, I've made wrapper. working well. no worries.

Ok! Please share the wrapper, it sounds like it could be useful for others.

library SetUpgradeable {
 struct AddressSet {
   uint256 id;
   mapping(uint256 => EnumerableSetUpgradeable.AddressSet) sets;
 }
 function clear(AddressSet storage data) internal {
   uint256 id= data.Id;
   delete data._addressSets[Id];
   data.id += 1;
 }
}

1 Like