Browse Source

Added an empty connection args check to the migration handler

Roland Haroutiounian 8 years ago
parent
commit
6fa7f8848f
1 changed files with 7 additions and 2 deletions
  1. 7
    2
      plugins/mongodb_datasource/migration_handler.py

+ 7
- 2
plugins/mongodb_datasource/migration_handler.py View File

@@ -12,6 +12,9 @@ class MigrationHandlerChangeError(Exception):
12 12
     pass
13 13
 
14 14
 
15
+class MigrationHandlerError(Exception):
16
+    pass
17
+
15 18
 @LodelHook('mongodb_mh_init_db')
16 19
 def mongodb_mh_init_db(conn_args=None):
17 20
     connection_args = get_connection_args('default') if conn_args is None else get_connection_args(conn_args['name'])
@@ -32,6 +35,9 @@ class MongoDbMigrationHandler(object):
32 35
     def __init__(self, conn_args=None, **kwargs):
33 36
         conn_args = get_connection_args() if conn_args is None else conn_args
34 37
 
38
+        if len(conn_args.keys()) == 0:
39
+            raise MigrationHandlerError("No connection arguments were given")
40
+
35 41
         #self.connection_name = conn_args['name']
36 42
         self.database = connect(host=conn_args['host'], port=conn_args['port'], db_name=conn_args['db_name'],
37 43
                                 username=conn_args['username'], password=conn_args['password'])
@@ -58,8 +64,7 @@ class MongoDbMigrationHandler(object):
58 64
     # @param collection_name str
59 65
     # @param charset str : default value is "utf8"
60 66
     # @param if_exists str : defines the behavior to have if the collection to create already exists (default value : "nothing")
61
-    def _create_collection(self, collection_name, charset='utf8',
62
-                           if_exists=MongoDbMigrationHandler.COMMANDS_IFEXISTS_NOTHING):
67
+    def _create_collection(self, collection_name, charset='utf8', if_exists=COMMANDS_IFEXISTS_NOTHING):
63 68
         if collection_name in self.database.collection_names(include_system_collections=False):
64 69
             if if_exists == MongoDbMigrationHandler.COMMANDS_IFEXISTS_DROP:
65 70
                 self._delete_collection(collection_name)

Loading…
Cancel
Save