mirror of
				https://github.com/psycopg/psycopg2.git
				synced 2025-11-04 01:37:31 +03:00 
			
		
		
		
	Fixed error in schema mismatch in composite caster
This commit is contained in:
		
							parent
							
								
									ba7a0a3008
								
							
						
					
					
						commit
						bb8e1e9455
					
				| 
						 | 
				
			
			@ -841,8 +841,8 @@ class CompositeCaster(object):
 | 
			
		|||
        tokens = self.tokenize(s)
 | 
			
		||||
        if len(tokens) != len(self.atttypes):
 | 
			
		||||
            raise psycopg2.DataError(
 | 
			
		||||
                "expecting %d components for the type %s, %d found instead",
 | 
			
		||||
                (len(self.atttypes), self.name, len(self.tokens)))
 | 
			
		||||
                "expecting %d components for the type %s, %d found instead" %
 | 
			
		||||
                (len(self.atttypes), self.name, len(tokens)))
 | 
			
		||||
 | 
			
		||||
        attrs = [ curs.cast(oid, token)
 | 
			
		||||
            for oid, token in zip(self.atttypes, tokens) ]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -648,6 +648,16 @@ class AdaptTypeTestCase(unittest.TestCase):
 | 
			
		|||
        self.assertEqual(v[1][1], "world")
 | 
			
		||||
        self.assertEqual(v[1][2], date(2011,1,3))
 | 
			
		||||
 | 
			
		||||
    @skip_if_no_composite
 | 
			
		||||
    def test_wrong_schema(self):
 | 
			
		||||
        oid = self._create_type("type_ii", [("a", "integer"), ("b", "integer")])
 | 
			
		||||
        from psycopg2.extras import CompositeCaster
 | 
			
		||||
        c = CompositeCaster('type_ii', oid, [('a', 23), ('b', 23), ('c', 23)])
 | 
			
		||||
        curs = self.conn.cursor()
 | 
			
		||||
        psycopg2.extensions.register_type(c.typecaster, curs)
 | 
			
		||||
        curs.execute("select (1,2)::type_ii")
 | 
			
		||||
        self.assertRaises(psycopg2.DataError, curs.fetchone)
 | 
			
		||||
 | 
			
		||||
    def _create_type(self, name, fields):
 | 
			
		||||
        curs = self.conn.cursor()
 | 
			
		||||
        try:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user