| @@ -4,6 +4,7 @@ Changelog | |||||||
|  |  | ||||||
| Changes in 0.6.X | Changes in 0.6.X | ||||||
| ================ | ================ | ||||||
|  | - Bug fix Read preference now passed correctly | ||||||
| - Added support for File like objects for GridFS | - Added support for File like objects for GridFS | ||||||
| - Fix for #473 - Dereferencing abstracts | - Fix for #473 - Dereferencing abstracts | ||||||
|  |  | ||||||
|   | |||||||
| @@ -63,7 +63,8 @@ def register_connection(alias, name, host='localhost', port=27017, | |||||||
|             'password': uri_dict.get('password'), |             'password': uri_dict.get('password'), | ||||||
|             'read_preference': read_preference, |             'read_preference': read_preference, | ||||||
|         }) |         }) | ||||||
|  |         if "replicaSet" in host: | ||||||
|  |             conn_settings['replicaSet'] = True | ||||||
|     _connection_settings[alias] = conn_settings |     _connection_settings[alias] = conn_settings | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -112,7 +113,11 @@ def get_connection(alias=DEFAULT_CONNECTION_NAME, reconnect=False): | |||||||
|             conn_settings['hosts_or_uri'] = conn_settings.pop('host', None) |             conn_settings['hosts_or_uri'] = conn_settings.pop('host', None) | ||||||
|             # Discard port since it can't be used on ReplicaSetConnection |             # Discard port since it can't be used on ReplicaSetConnection | ||||||
|             conn_settings.pop('port', None) |             conn_settings.pop('port', None) | ||||||
|  |             # Discard replicaSet if not base string | ||||||
|  |             if not isinstance(conn_settings['replicaSet'], basestring): | ||||||
|  |                 conn_settings.pop('replicaSet', None) | ||||||
|             connection_class = ReplicaSetConnection |             connection_class = ReplicaSetConnection | ||||||
|  |  | ||||||
|         try: |         try: | ||||||
|             _connections[alias] = connection_class(**conn_settings) |             _connections[alias] = connection_class(**conn_settings) | ||||||
|         except Exception, e: |         except Exception, e: | ||||||
|   | |||||||
							
								
								
									
										28
									
								
								tests/replicaset_connection.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								tests/replicaset_connection.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,28 @@ | |||||||
|  | import unittest | ||||||
|  | import pymongo | ||||||
|  | from pymongo import ReadPreference | ||||||
|  |  | ||||||
|  | import mongoengine | ||||||
|  | from mongoengine import * | ||||||
|  | from mongoengine.connection import get_db, get_connection, ConnectionError | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class ConnectionTest(unittest.TestCase): | ||||||
|  |  | ||||||
|  |     def tearDown(self): | ||||||
|  |         mongoengine.connection._connection_settings = {} | ||||||
|  |         mongoengine.connection._connections = {} | ||||||
|  |         mongoengine.connection._dbs = {} | ||||||
|  |  | ||||||
|  |     def test_replicaset_uri_passes_read_preference(self): | ||||||
|  |         """Requires a replica set called "rs" on port 27017 | ||||||
|  |         """ | ||||||
|  |         try: | ||||||
|  |             conn = connect(db='mongoenginetest', host="mongodb://localhost/mongoenginetest?replicaSet=rs", read_preference=ReadPreference.SECONDARY_ONLY) | ||||||
|  |         except ConnectionError, e: | ||||||
|  |             return | ||||||
|  |  | ||||||
|  |         self.assertEquals(conn.read_preference, ReadPreference.SECONDARY_ONLY) | ||||||
|  |  | ||||||
|  | if __name__ == '__main__': | ||||||
|  |     unittest.main() | ||||||
		Reference in New Issue
	
	Block a user