Skip to content

Commit 2d7b6df

Browse files
committed
Unconditional config validation on rule-add, fill defaults during validation
1 parent 69c5723 commit 2d7b6df

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

api/jobs/gears.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def validate_gear_config(gear, config_):
111111
validator = Draft4Validator(ci)
112112

113113
try:
114-
validator.validate(config_)
114+
validator.validate(fill_gear_default_values(gear, config_))
115115
except ValidationError as err:
116116
key = None
117117
if len(err.relative_path) > 0:

api/jobs/handlers.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
from ..auth.apikeys import JobApiKey
2323

24-
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
24+
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
2525
from .jobs import Job, Logs
2626
from .batch import check_state, update
2727
from .queue import Queue
@@ -183,8 +183,7 @@ def post(self, cid):
183183

184184
doc['project_id'] = cid
185185

186-
if 'config' in doc:
187-
validate_gear_config(gear, fill_gear_default_values(gear, doc['config']))
186+
validate_gear_config(gear, doc.get('config'))
188187

189188
result = config.db.project_rules.insert_one(doc)
190189
return { '_id': result.inserted_id }
@@ -239,8 +238,7 @@ def put(self, cid, rid):
239238

240239
if 'alg' in updates or 'config' in updates:
241240
gear = get_gear_by_name(updates.get('alg', doc['alg']))
242-
config_ = fill_gear_default_values(gear, updates.get('config', doc.get('config', {})))
243-
validate_gear_config(gear, config_)
241+
validate_gear_config(gear, updates.get('config', doc.get('config')))
244242

245243
doc.update(updates)
246244
config.db.project_rules.replace_one({'_id': bson.ObjectId(rid)}, doc)
@@ -539,7 +537,7 @@ def post(self):
539537
gear = get_gear(gear_id)
540538
if gear.get('gear', {}).get('custom', {}).get('flywheel', {}).get('invalid', False):
541539
self.abort(400, 'Gear marked as invalid, will not run!')
542-
validate_gear_config(gear, fill_gear_default_values(gear, config_))
540+
validate_gear_config(gear, config_)
543541

544542
container_ids = []
545543
container_type = None

api/jobs/queue.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def enqueue_job(job_map, origin, perm_check_uid=None):
156156
if gear.get('gear', {}).get('custom', {}).get('flywheel', {}).get('invalid', False):
157157
raise InputValidationException('Gear marked as invalid, will not run!')
158158

159-
config_ = fill_gear_default_values(gear, job_map.get('config', {}))
159+
config_ = job_map.get('config', {})
160160
validate_gear_config(gear, config_)
161161

162162
# Translate maps to FileReferences
@@ -195,7 +195,7 @@ def enqueue_job(job_map, origin, perm_check_uid=None):
195195

196196
# Config options are stored on the job object under the "config" key
197197
config_ = {
198-
'config': config_,
198+
'config': fill_gear_default_values(gear, config_),
199199
'inputs': { },
200200
'destination': {
201201
'type': destination.type,

0 commit comments

Comments
 (0)