Skip to content

Commit

Permalink
Fix schema updater mess.
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterKraus committed Aug 21, 2024
1 parent e8cbdfd commit 0ed35ff
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/yadg/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ def process_schema(dataschema: DataSchema, strict_merge: bool = False) -> DataTr
root.attrs.update(dgutils.get_yadg_metadata())

while hasattr(dataschema, "update"):
dataschema = dataschema.update()
if hasattr(dataschema, "metadata"):
if hasattr(dataschema.metadata, "version"):
if dataschema.metadata.version == "5.0":
break
dataschema = dataschema.update()

for si, step in enumerate(dataschema.steps):
logger.info("Processing step %d:", si)
Expand Down
4 changes: 4 additions & 0 deletions src/yadg/dgutils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ def update_schema(object: Union[list, dict]) -> dict:
raise ValueError(f"Supplied object is of incorrect type: {type(object)}")
newobj = to_dataschema(**newobj)
while hasattr(newobj, "update"):
if hasattr(newobj, "metadata"):
if hasattr(newobj.metadata, "version"):
if newobj.metadata.version == "5.0":
break
newobj = newobj.update()
return newobj

Expand Down
3 changes: 2 additions & 1 deletion src/yadg/subcommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ def process(args: argparse.Namespace) -> None:
logger.info("Loaded dataschema version '%s'", ds.metadata.version)

while hasattr(ds, "update"):
ds = ds.update()
if hasattr(ds, "metadata"):
if hasattr(ds.metadata, "version"):
if ds.metadata.version == "5.0":
break
ds = ds.update()


logger.debug("Processing schema")
datagram = core.process_schema(ds, strict_merge=not args.ignore_merge_errors)
Expand Down
4 changes: 4 additions & 0 deletions tests/test_preset.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def test_preset(input, ts, datadir):

schema = to_dataschema(**preset)
while hasattr(schema, "update"):
if hasattr(schema, "metadata"):
if hasattr(schema.metadata, "version"):
if schema.metadata.version == "5.0":
break
schema = schema.update()
ds = yadg.dgutils.schema_from_preset(schema, input)

Expand Down

0 comments on commit 0ed35ff

Please sign in to comment.