From 2d7b6df70c98da08e3acea061842e81a0c1a25c7 Mon Sep 17 00:00:00 2001 From: Ambrus Simon Date: Tue, 31 Oct 2017 13:11:29 -0500 Subject: [PATCH] Unconditional config validation on rule-add, fill defaults during validation --- api/jobs/gears.py | 2 +- api/jobs/handlers.py | 10 ++++------ api/jobs/queue.py | 4 ++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/api/jobs/gears.py b/api/jobs/gears.py index 59d64240d..51da45584 100644 --- a/api/jobs/gears.py +++ b/api/jobs/gears.py @@ -111,7 +111,7 @@ def validate_gear_config(gear, config_): validator = Draft4Validator(ci) try: - validator.validate(config_) + validator.validate(fill_gear_default_values(gear, config_)) except ValidationError as err: key = None if len(err.relative_path) > 0: diff --git a/api/jobs/handlers.py b/api/jobs/handlers.py index 9e0a99187..76ba8dc1d 100644 --- a/api/jobs/handlers.py +++ b/api/jobs/handlers.py @@ -21,7 +21,7 @@ from ..auth.apikeys import JobApiKey -from .gears import validate_gear_config, get_gears, get_gear, get_invocation_schema, remove_gear, upsert_gear, suggest_container, get_gear_by_name, check_for_gear_insertion, fill_gear_default_values +from .gears import validate_gear_config, get_gears, get_gear, get_invocation_schema, remove_gear, upsert_gear, suggest_container, get_gear_by_name, check_for_gear_insertion from .jobs import Job, Logs from .batch import check_state, update from .queue import Queue @@ -183,8 +183,7 @@ def post(self, cid): doc['project_id'] = cid - if 'config' in doc: - validate_gear_config(gear, fill_gear_default_values(gear, doc['config'])) + validate_gear_config(gear, doc.get('config')) result = config.db.project_rules.insert_one(doc) return { '_id': result.inserted_id } @@ -239,8 +238,7 @@ def put(self, cid, rid): if 'alg' in updates or 'config' in updates: gear = get_gear_by_name(updates.get('alg', doc['alg'])) - config_ = fill_gear_default_values(gear, updates.get('config', doc.get('config', {}))) - validate_gear_config(gear, config_) + validate_gear_config(gear, updates.get('config', doc.get('config'))) doc.update(updates) config.db.project_rules.replace_one({'_id': bson.ObjectId(rid)}, doc) @@ -539,7 +537,7 @@ def post(self): gear = get_gear(gear_id) if gear.get('gear', {}).get('custom', {}).get('flywheel', {}).get('invalid', False): self.abort(400, 'Gear marked as invalid, will not run!') - validate_gear_config(gear, fill_gear_default_values(gear, config_)) + validate_gear_config(gear, config_) container_ids = [] container_type = None diff --git a/api/jobs/queue.py b/api/jobs/queue.py index 3f057c20f..c5bf2b73e 100644 --- a/api/jobs/queue.py +++ b/api/jobs/queue.py @@ -156,7 +156,7 @@ def enqueue_job(job_map, origin, perm_check_uid=None): if gear.get('gear', {}).get('custom', {}).get('flywheel', {}).get('invalid', False): raise InputValidationException('Gear marked as invalid, will not run!') - config_ = fill_gear_default_values(gear, job_map.get('config', {})) + config_ = job_map.get('config', {}) validate_gear_config(gear, config_) # Translate maps to FileReferences @@ -195,7 +195,7 @@ def enqueue_job(job_map, origin, perm_check_uid=None): # Config options are stored on the job object under the "config" key config_ = { - 'config': config_, + 'config': fill_gear_default_values(gear, config_), 'inputs': { }, 'destination': { 'type': destination.type,