Fix some bugs with link uid types after saving and loading.

This commit is contained in:
AccentuSoft
2022-01-06 21:58:54 +02:00
parent 1a35c2c7fd
commit 83c9771c5e
2 changed files with 7 additions and 6 deletions

View File

@@ -4,6 +4,7 @@ from shutil import move
from msgpack import load, dump
from threading import Lock
from pathlib import Path
from typing import Union
import networkx as nx
@@ -314,14 +315,14 @@ class EntitiesDB:
self.dbLock.release()
return returnValue
def isNode(self, uid: str):
def isNode(self, uid: Union[str, list, tuple]):
"""
Returns True if the uid (primary attribute) given exists as
an entity, and False otherwise.
"""
self.dbLock.acquire()
returnValue = False
if self.database.nodes.get(uid) is not None:
if isinstance(uid, str) and self.database.nodes.get(uid) is not None:
returnValue = True
self.dbLock.release()
return returnValue
@@ -337,14 +338,13 @@ class EntitiesDB:
return True
return False
def isLink(self, uid: tuple):
def isLink(self, uid: Union[str, list, tuple]):
"""
Returns True if the uid given exists as a link, and False otherwise.
"""
self.dbLock.acquire()
returnValue = False
item = self.database.edges.get(uid)
if item is not None:
if isinstance(uid, tuple) and self.database.edges.get(uid) is not None:
returnValue = True
self.dbLock.release()
return returnValue

View File

@@ -298,7 +298,8 @@ class ResourceHandler:
returnGraph.add_node(node, **graphNodes[node])
for edge in graphEdges:
edgeUID = literal_eval(edge)
edgeUID = tuple(literal_eval(edge))
graphEdges[edge]['uid'] = edgeUID
returnGraph.add_edge(*edgeUID, **graphEdges[edge])
return returnGraph