mirror of
				https://github.com/psycopg/psycopg2.git
				synced 2025-10-31 15:57:31 +03:00 
			
		
		
		
	Decimal adapter registration moved from C to Python
Fixes Decimal adaptation in sub-interpreter, where the Decimal class has a different identity from the one in the main interpreter. Closes ticket #52.
This commit is contained in:
		
							parent
							
								
									6da39e3a37
								
							
						
					
					
						commit
						dde4c0de3d
					
				
							
								
								
									
										2
									
								
								NEWS
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								NEWS
									
									
									
									
									
								
							|  | @ -6,6 +6,8 @@ What's new in psycopg 2.4.3 | ||||||
|   - Added support for arrays of hstores and composite types (ticket #66). |   - Added support for arrays of hstores and composite types (ticket #66). | ||||||
|   - Fixed segfault in case of transaction started with connection lost |   - Fixed segfault in case of transaction started with connection lost | ||||||
|     (and possibly other events). |     (and possibly other events). | ||||||
|  |   - Fixed adaptation of Decimal type in sub-interpreters, such as in | ||||||
|  |     certain mod_wsgi configurations (ticket #52). | ||||||
|   - Rollback connections in transaction or in error before putting them |   - Rollback connections in transaction or in error before putting them | ||||||
|     back into a pool. Also discard broken connections (ticket #62). |     back into a pool. Also discard broken connections (ticket #62). | ||||||
|   - Lazy import of the slow uuid module, thanks to Marko Kreen. |   - Lazy import of the slow uuid module, thanks to Marko Kreen. | ||||||
|  |  | ||||||
|  | @ -85,5 +85,17 @@ import psycopg2.extensions as _ext | ||||||
| _ext.register_adapter(tuple, _ext.SQL_IN) | _ext.register_adapter(tuple, _ext.SQL_IN) | ||||||
| _ext.register_adapter(type(None), _ext.NoneAdapter) | _ext.register_adapter(type(None), _ext.NoneAdapter) | ||||||
| 
 | 
 | ||||||
|  | # Register the Decimal adapter here instead of in the C layer. | ||||||
|  | # This way a new class is registered for each sub-interpreter. | ||||||
|  | # See ticket #52 | ||||||
|  | try: | ||||||
|  |     from decimal import Decimal | ||||||
|  | except ImportError: | ||||||
|  |     pass | ||||||
|  | else: | ||||||
|  |     from psycopg2._psycopg import Decimal as Adapter | ||||||
|  |     _ext.register_adapter(Decimal, Adapter) | ||||||
|  |     del Decimal, Adapter | ||||||
|  | 
 | ||||||
| __all__ = filter(lambda k: not k.startswith('_'), locals().keys()) | __all__ = filter(lambda k: not k.startswith('_'), locals().keys()) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -322,7 +322,6 @@ static void | ||||||
| psyco_adapters_init(PyObject *mod) | psyco_adapters_init(PyObject *mod) | ||||||
| { | { | ||||||
|     PyObject *call; |     PyObject *call; | ||||||
|     PyTypeObject *type; |  | ||||||
| 
 | 
 | ||||||
|     microprotocols_add(&PyFloat_Type, NULL, (PyObject*)&pfloatType); |     microprotocols_add(&PyFloat_Type, NULL, (PyObject*)&pfloatType); | ||||||
| #if PY_MAJOR_VERSION < 3 | #if PY_MAJOR_VERSION < 3 | ||||||
|  | @ -353,9 +352,6 @@ psyco_adapters_init(PyObject *mod) | ||||||
| 
 | 
 | ||||||
|     microprotocols_add(&PyList_Type, NULL, (PyObject*)&listType); |     microprotocols_add(&PyList_Type, NULL, (PyObject*)&listType); | ||||||
| 
 | 
 | ||||||
|     if ((type = (PyTypeObject*)psyco_GetDecimalType()) != NULL) |  | ||||||
|         microprotocols_add(type, NULL, (PyObject*)&pdecimalType); |  | ||||||
| 
 |  | ||||||
|     /* the module has already been initialized, so we can obtain the callable
 |     /* the module has already been initialized, so we can obtain the callable
 | ||||||
|        objects directly from its dictionary :) */ |        objects directly from its dictionary :) */ | ||||||
|     call = PyMapping_GetItemString(mod, "DateFromPy"); |     call = PyMapping_GetItemString(mod, "DateFromPy"); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user