diff --git a/src/keri/app/habbing.py b/src/keri/app/habbing.py index 9b8a9f26e..09daca0c9 100644 --- a/src/keri/app/habbing.py +++ b/src/keri/app/habbing.py @@ -689,6 +689,8 @@ def deleteHab(self, name): del self.habs[hab.pre] self.db.prefixes.remove(hab.pre) + if hab.pre in self.db.gids: + self.db.gids.remove(hab.pre) return True diff --git a/src/keri/db/basing.py b/src/keri/db/basing.py index b3f00d3bf..23544fe92 100644 --- a/src/keri/db/basing.py +++ b/src/keri/db/basing.py @@ -68,52 +68,6 @@ class komerdict(dict): record from dataabase to class instance. if no mapping function then just return the dataclass record as value. """ - __slots__ = ('db') # no .__dict__ just for db reference - - def __init__(self, *pa, **kwa): - super(dbdict, self).__init__(*pa, **kwa) - self.db = None - - def __getitem__(self, k): - try: - return super(dbdict, self).__getitem__(k) - except KeyError as ex: - if not self.db: - raise ex # reraise KeyError - if (ksr := self.db.states.get(keys=k)) is None: - raise ex # reraise KeyError - try: - kever = eventing.Kever(state=ksr, db=self.db) - except kering.MissingEntryError: # no kel event for keystate - raise ex # reraise KeyError - self.__setitem__(k, kever) - return kever - - def __contains__(self, k): - if not super(dbdict, self).__contains__(k): - try: - self.__getitem__(k) - return True - except KeyError: - return False - else: - return True - - def get(self, k, default=None): - """Override of dict get method - - Parameters: - k (str): key for dict - default: default value to return if not found - - Returns: - kever: converted from underlying dict or database - - """ - if not super(dbdict, self).__contains__(k): - return default - else: - return self.__getitem__(k) ''' @@ -1198,6 +1152,9 @@ def reload(self): continue self.kevers[kever.prefixer.qb64] = kever self.prefixes.add(kever.prefixer.qb64) + if data.mid: # group hab + self.gids.add(data.hid) + elif data.mid is None: # in .habs but no corresponding key state and not a group so remove removes.append(keys) # no key state or KEL event for .hab record @@ -1217,6 +1174,8 @@ def reload(self): continue self.kevers[kever.prefixer.qb64] = kever self.prefixes.add(kever.prefixer.qb64) + if data.mid: # group hab + self.gids.add(data.hid) elif data.mid is None: # in .habs but no corresponding key state and not a group so remove removes.append(keys) # no key state or KEL event for .hab record @@ -1238,7 +1197,7 @@ def clean(self): temp=self.temp, headDirPath=self.headDirPath, perm=self.perm, - clean=True) as copy: + clean=True) as copy: # copy is Baser instance with reopenDB(db=self, reuse=True, readonly=True): # reopen as readonly if not os.path.exists(self.path): @@ -1262,7 +1221,12 @@ def clean(self): if val.hid in copy.kevers: # only copy habs that verified copy.habs.put(keys=keys, val=val) copy.prefixes.add(val.hid) + if val.mid: # a group hab + copy.gids.add(val.hid) + # ToDo XXXX + # is this obsolete? Should this be removed or should this be + # be the Signator name not the default name of the Habery? if not copy.habs.get(keys=(self.name,)): raise ValueError("Error cloning habs, missing orig name={}." "".format(self.name)) @@ -1299,6 +1263,10 @@ def clean(self): self.prefixes.clear() self.prefixes.update(copy.prefixes) + # clear and clone .gids + self.gids.clear() + self.gids.update(copy.gids) + with reopenDB(db=self, reuse=True): # make sure can reopen if not isinstance(self.env, lmdb.Environment): raise ValueError("Error cloning, unable to reopen." diff --git a/tests/db/test_basing.py b/tests/db/test_basing.py index cf0e9ff60..14a4bd8ef 100644 --- a/tests/db/test_basing.py +++ b/tests/db/test_basing.py @@ -1708,7 +1708,7 @@ def test_clean_baser(): name = "nat" # with basing.openDB(name="nat") as natDB, keeping.openKS(name="nat") as natKS: with habbing.openHby(name=name) as hby: # default is temp=True - natHab = hby.makeHab(name=name, isith='2', icount=3) + natHab = hby.makeHab(name=name, isith='2', icount=3) # default Hab # setup Nat's habitat using default salt multisig already incepts #natHab = habbing.Habitat(name='nat', ks=natKS, db=natDB, #isith='2', icount=3, temp=True)