dataimport.py
brancholdstable
changeset 8462 a14b6562082b
parent 8406 f3bc8ca0b715
child 8625 7ee0752178e5
child 8723 d2472948da9c
--- a/dataimport.py	Tue Feb 14 15:14:22 2012 +0100
+++ b/dataimport.py	Tue Jul 10 15:07:23 2012 +0200
@@ -182,7 +182,10 @@
     assert isinstance(row, dict)
     assert isinstance(map, list)
     for src, dest, funcs in map:
-        res[dest] = row[src]
+        try:
+            res[dest] = row[src]
+        except KeyError:
+            continue
         try:
             for func in funcs:
                 res[dest] = func(res[dest])
@@ -446,9 +449,12 @@
         if session is None:
             sys.exit('please provide a session of run this script with cubicweb-ctl shell and pass cnx as session')
         if not hasattr(session, 'set_cnxset'):
-            # connection
-            cnx = session
-            session = session.request()
+            if hasattr(session, 'request'):
+                # connection object
+                cnx = session
+                session = session.request()
+            else: # object is already a request
+                cnx = session.cnx
             session.set_cnxset = lambda : None
             commit = commit or cnx.commit
         else: