mirror of
				https://github.com/psycopg/psycopg2.git
				synced 2025-11-04 09:47:30 +03:00 
			
		
		
		
	Classify connection exceptions as operational errors to better conform with PEP 249
This commit is contained in:
		
							parent
							
								
									8764a85320
								
							
						
					
					
						commit
						cdca0a20e0
					
				
							
								
								
									
										9
									
								
								NEWS
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								NEWS
									
									
									
									
									
								
							| 
						 | 
					@ -1,6 +1,15 @@
 | 
				
			||||||
Current release
 | 
					Current release
 | 
				
			||||||
---------------
 | 
					---------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					What's new in psycopg 2.9.0
 | 
				
			||||||
 | 
					^^^^^^^^^^^^^^^^^^^^^^^^^^^
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- Reclassified SQLSTATE connection exceptions (08XXX) as
 | 
				
			||||||
 | 
					  `~psycopg2.errors.OperationalError`, conforming better to
 | 
				
			||||||
 | 
					  PEP 249.  This error is a subclass of previously used
 | 
				
			||||||
 | 
					  `~psycopg2.errors.DatabaseError`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
What's new in psycopg 2.8.6
 | 
					What's new in psycopg 2.8.6
 | 
				
			||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^
 | 
					^^^^^^^^^^^^^^^^^^^^^^^^^^^
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -65,6 +65,8 @@ base_exception_from_sqlstate(const char *sqlstate)
 | 
				
			||||||
    switch (sqlstate[0]) {
 | 
					    switch (sqlstate[0]) {
 | 
				
			||||||
    case '0':
 | 
					    case '0':
 | 
				
			||||||
        switch (sqlstate[1]) {
 | 
					        switch (sqlstate[1]) {
 | 
				
			||||||
 | 
					        case '8': /* Class 08 - Connection Exception */
 | 
				
			||||||
 | 
					            return OperationalError;
 | 
				
			||||||
        case 'A': /* Class 0A - Feature Not Supported */
 | 
					        case 'A': /* Class 0A - Feature Not Supported */
 | 
				
			||||||
            return NotSupportedError;
 | 
					            return NotSupportedError;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -62,6 +62,13 @@ class ErrorsTests(ConnectingTestCase):
 | 
				
			||||||
        with self.assertRaises(KeyError):
 | 
					        with self.assertRaises(KeyError):
 | 
				
			||||||
            errors.lookup('XXXXX')
 | 
					            errors.lookup('XXXXX')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_connection_exceptions_backwards_compatibility(self):
 | 
				
			||||||
 | 
					        err = errors.lookup('08000')
 | 
				
			||||||
 | 
					        # connection exceptions are classified as operational errors
 | 
				
			||||||
 | 
					        self.assert_(issubclass(err, errors.OperationalError))
 | 
				
			||||||
 | 
					        # previously these errors were classified only as DatabaseError
 | 
				
			||||||
 | 
					        self.assert_(issubclass(err, errors.DatabaseError))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_has_base_exceptions(self):
 | 
					    def test_has_base_exceptions(self):
 | 
				
			||||||
        excs = []
 | 
					        excs = []
 | 
				
			||||||
        for n in dir(psycopg2):
 | 
					        for n in dir(psycopg2):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user