changeset 636:9fb784c1f23d

changed insert_ methods in sql to not clobber internal keys STATUS, PRIORITY, HASH
author James Bergstra <bergstrj@iro.umontreal.ca>
date Wed, 21 Jan 2009 16:01:16 -0500
parents e52a5c3aaca5
children 83397981a118
files pylearn/dbdict/sql.py
diffstat 1 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/pylearn/dbdict/sql.py	Tue Jan 20 23:32:24 2009 -0500
+++ b/pylearn/dbdict/sql.py	Wed Jan 21 16:01:16 2009 -0500
@@ -231,9 +231,12 @@
 
     rval = None
     if do_insert:
-        job[STATUS] = START
-        job[HASH] = jobhash
-        job[PRIORITY] = priority
+        if STATUS not in job:
+            job[STATUS] = START
+        if HASH not in job:
+            job[HASH] = jobhash
+        if PRIORITY not in job:
+            job[PRIORITY] = priority
         rval = db.insert(job, session=s)
         s.commit()
 
@@ -244,7 +247,12 @@
 
 def insert_job(experiment_fn, state, db, force_dup=False, session=None, priority=1.0):
     state = copy.copy(state)
-    state[EXPERIMENT] = experiment_fn.__module__ + '.' + experiment_fn.__name__
+    experiment_name = experiment_fn.__module__ + '.' + experiment_fn.__name__
+    if EXPERIMENT in state:
+        if state[EXPERIMENT] != experiment_name:
+            raise Exception('Inconsistency: state element %s does not match experiment %s' %(EXPERIMENT, experiment_name))
+    else:
+        state[EXPERIMENT] = experiment_name
     return insert_dict(state, db, force_dup=force_dup, session=session, priority=priority)