@@ -681,27 +681,31 @@ def test_drop_table_tablemetadata_unavailable(self):
681681 def test_ignore_decode_errors (self ):
682682 problematic_unicode_string = b'[{"text":"\xed \xa0 \xbd \xed \xb1 \x8d Some string"}]'
683683 self .stream .close ()
684- self .execute ("CREATE TABLE test (id INTEGER(11), data VARCHAR(50))" )
684+ self .execute ("CREATE TABLE test (id INTEGER(11), data VARCHAR(50) CHARACTER SET utf8mb4 )" )
685685 self .execute ("INSERT INTO test VALUES (1, 'A value')" )
686686 self .execute ("COMMIT" )
687- self .execute ("ALTER TABLE test MODIFY COLUMN data VARCHAR(50) CHARACTER SET utf8mb4" )
688687 self .execute_with_args ("INSERT INTO test (id, data) VALUES (%s, %s)" , (2 , problematic_unicode_string ))
689688 self .execute ("COMMIT" )
690689
690+ # Initialize with ignore_decode_errors=False
691691 self .stream = BinLogStreamReader (
692692 self .database ,
693693 server_id = 1024 ,
694694 only_events = (WriteRowsEvent ,),
695695 ignore_decode_errors = False
696696 )
697- try :
698- self .stream .fetchone ()
699- self .stream .fetchone ()
700- except UnicodeDecodeError as e :
701- self .fail ("raised unexpected exception: {exception}" .format (exception = e ))
702- finally :
703- self .resetBinLog ()
697+ self .stream .fetchone ()
698+ self .stream .fetchone ()
699+ self .stream .fetchone ()
700+ event = self .stream .fetchone () # insert for row 1
701+ data = event .rows [0 ]["values" ]["data" ]
702+ self .assertEqual (data , 'A value' )
704703
704+ with self .assertRaises (UnicodeError ) as exception :
705+ event = self .stream .fetchone () # insert for row 2
706+ data = event .rows [0 ]["values" ]["data" ]
707+
708+ # Initialize with ignore_decode_errors=False
705709 self .stream = BinLogStreamReader (
706710 self .database ,
707711 server_id = 1024 ,
@@ -710,8 +714,14 @@ def test_ignore_decode_errors(self):
710714 )
711715 self .stream .fetchone ()
712716 self .stream .fetchone ()
713-
714- self .resetBinLog ()
717+ self .stream .fetchone ()
718+ event = self .stream .fetchone () # insert for row 1
719+ data = event .rows [0 ]["values" ]["data" ]
720+ self .assertEqual (data , 'A value' )
721+
722+ event = self .stream .fetchone () # insert for row 2
723+ data = event .rows [0 ]["values" ]["data" ]
724+ self .assertEqual (data , '[{"text":" Some string"}]' )
715725
716726 def test_drop_column (self ):
717727 self .stream .close ()
0 commit comments