Skip to content

Commit

Permalink
TEMP_getChildren returns also source document attribtue (to be null'd…
Browse files Browse the repository at this point in the history
… if invalid)
  • Loading branch information
eudoxos committed Nov 21, 2024
1 parent a7a08db commit 245b40d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
15 changes: 7 additions & 8 deletions mupifDB/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class DbRef_Model(StrictBase):
class TEMP_DbLookup_Model(StrictBase):
where: str
attrs: List[str]
values: List[str]
values: List[str|int]

class MongoObjBase_Model(StrictBase):
dbID: Optional[DatabaseID]=Field(None,alias='_id') # type: ignore[arg-type]
Expand All @@ -53,7 +53,7 @@ def model_dump_db(self):
ret=self.model_dump(mode='json')
if '_id' in ret and ret['_id'] is None: del ret['_id']
return ret
def TEMP_getChildren(self) -> List[DbRef_Model]: return []
def TEMP_getChildren(self) -> List[Tuple[str,DbRef_Model]]: return []
def TEMP_getLookupChildren(self) -> List[TEMP_DbLookup_Model]: return []

import abc
Expand Down Expand Up @@ -148,8 +148,8 @@ class Link_Model(StrictBase):
FileID: Optional[str]=None
Compulsory: Optional[bool]=False # deema: allow None
Object: dict[str,Any]
def TEMP_getChildren(self) -> List[DbRef_Model]:
return [DbRef_Model(where=where,id=id) for where,id in [('fs.files',self.FileID)] if id is not None and id!='']
def TEMP_getChildren(self) -> List[Tuple[str,DbRef_Model]]:
return [('FileID',DbRef_Model(where=where,id=id)) for where,id in [('fs.files',self.FileID)] if id is not None and id!='']

class IODataRecord_Model(MongoObj_Model):
DataSet: List[IODataRecordItem_Model]=[]
Expand Down Expand Up @@ -188,8 +188,7 @@ class Output_Model(InputOutputBase_Model):
EDMMapping: List[EDMMapping_Model]=[]
Version: int=1

# TODO: WorkflowID==self.wid and WorkflowVersion==self.Version
def TEMP_getLookupChildren(self) -> List[TEMP_DbLookup_Model]: return [TEMP_DbLookup_Model(where='WorkflowExecutions',attrs=['WorkflowID'],values=[self.wid])]
def TEMP_getLookupChildren(self) -> List[TEMP_DbLookup_Model]: return [TEMP_DbLookup_Model(where='WorkflowExecutions',attrs=['WorkflowID','WorkflowVersion'],values=[self.wid,self.Version])]


class WorkflowExecution_Model(MongoObj_Model):
Expand All @@ -213,8 +212,8 @@ class WorkflowExecution_Model(MongoObj_Model):
Inputs: str
Outputs: str

def TEMP_getChildren(self) -> List[DbRef_Model]:
return [DbRef_Model(where=where,id=id) for where,id in [('IOData',self.Inputs),('IOData',self.Outputs),('fs.files',self.ExecutionLog)] if id is not None and id!='']
def TEMP_getChildren(self) -> List[Tuple[str,DbRef_Model]]:
return [(attr,DbRef_Model(where=where,id=id)) for where,id,attr in [('IOData',self.Inputs,'Inputs'),('IOData',self.Outputs,'Outputs'),('fs.files',self.ExecutionLog,'ExecutionLog')] if id is not None and id!='']



Expand Down
10 changes: 6 additions & 4 deletions tools/database-add-parents.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

dbPort=27001
dbPort=27017

from pymongo import MongoClient
import pymongo
import pymongo.errors
from bson import ObjectId
import bson, bson.objectid
from rich import print_json
Expand Down Expand Up @@ -105,7 +106,7 @@ def set_attr_null(dbColl,obj,attr):
progress.update(doc_task,description=' ↳[cyan]…',start=False,visible=False)
progress.update(chi_task,description=' ↳[yellow]…',start=False,visible=False)

client = MongoClient(f'mongodb://localhost:27017')
client = MongoClient(f'mongodb://localhost:{dbPort}')
db = client.MuPIF
progress.reset(col_task,start=True)
progress.update(col_task,description='↳[green]…',total=len(coll2model),completed=0,visible=True)
Expand All @@ -125,10 +126,11 @@ def set_attr_null(dbColl,obj,attr):
try:
obj=Model.model_validate(rec)
thisRef=models.DbRef_Model(where=coll,id=obj.dbID)
for i,cref in enumerate(obj.TEMP_getChildren()):
for i,(attr,cref) in enumerate(obj.TEMP_getChildren()):
child=resolve_DbRef(db,cref)
if child is None:
log.error(f'Unresolvable child {cref=} (setting to null not yet implemented)')
log.error(f'Unresolvable child {cref=}; setting {attr=} to null!')
set_attr_null(dbColl,obj,attr)
print_mongo(rec)
continue
if child.parent is None:
Expand Down

0 comments on commit 245b40d

Please sign in to comment.