Skip to content

Commit

Permalink
Unconditional config validation on rule-add, fill defaults during val…
Browse files Browse the repository at this point in the history
…idation
  • Loading branch information
ambrussimon committed Oct 31, 2017
1 parent 69c5723 commit 2d7b6df
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion api/jobs/gears.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 4 additions & 6 deletions api/jobs/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions api/jobs/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 2d7b6df

Please sign in to comment.