Skip to content

Commit

Permalink
#2201: fix bug in schema; require collection_id for migratable objects
Browse files Browse the repository at this point in the history
  • Loading branch information
cwschilly authored and cz4rs committed Sep 20, 2024
1 parent 12fdfc8 commit 2c76bc2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
9 changes: 5 additions & 4 deletions scripts/JSON_data_files_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,13 +434,14 @@ def validate_comm_links(all_jsons):

for data in all_jsons:
tasks = data["phases"][n]["tasks"]
id_key = "id" if "id" in tasks[0]["entity"] else "seq_id"
task_ids.update({int(task["entity"][id_key]) for task in tasks})
task_ids.update(
{int(task["entity"].get("id", task["entity"].get("seq_id"))) for task in tasks}
)

if data["phases"][n].get("communications") is not None:
comms = data["phases"][n]["communications"]
comm_ids.update({int(comm["from"][id_key]) for comm in comms})
comm_ids.update({int(comm["to"][id_key]) for comm in comms})
comm_ids.update({int(comm["from"].get("id", comm["from"].get("seq_id"))) for comm in comms})
comm_ids.update({int(comm["to"].get("id", comm["to"].get("seq_id"))) for comm in comms})

if not comm_ids.issubset(task_ids):
logging.error(
Expand Down
17 changes: 12 additions & 5 deletions scripts/LBDatafile_schema.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
from schema import And, Optional, Schema

def validate_id_and_seq_id(field):
"""Ensure that either seq_id or id is provided."""
def validate_ids(field):
"""
Ensure that 1) either seq_id or id is provided,
and 2) if an object is migratable, collection_id has been set.
"""
if 'seq_id' not in field and 'id' not in field:
raise ValueError('Either id (bit-encoded) or seq_id must be provided.')

if field['migratable'] and 'collection_id' not in field:
raise ValueError('If an entity is migratable, it must have a collection_id')

return field

LBDatafile_schema = Schema(
Expand Down Expand Up @@ -45,7 +52,7 @@ def validate_id_and_seq_id(field):
'type': str,
'migratable': bool,
Optional('objgroup_id'): int
}, validate_id_and_seq_id),
}, validate_ids),
'node': int,
'resource': str,
Optional('subphases'): [
Expand All @@ -71,7 +78,7 @@ def validate_id_and_seq_id(field):
Optional('migratable'): bool,
Optional('index'): [int],
Optional('objgroup_id'): int,
}, validate_id_and_seq_id),
}, validate_ids),
'messages': int,
'from': And({
'type': str,
Expand All @@ -82,7 +89,7 @@ def validate_id_and_seq_id(field):
Optional('migratable'): bool,
Optional('index'): [int],
Optional('objgroup_id'): int,
}, validate_id_and_seq_id),
}, validate_ids),
'bytes': float
}
],
Expand Down

0 comments on commit 2c76bc2

Please sign in to comment.