@@ -681,27 +681,31 @@ def test_drop_table_tablemetadata_unavailable(self):
681
681
def test_ignore_decode_errors (self ):
682
682
problematic_unicode_string = b'[{"text":"\xed \xa0 \xbd \xed \xb1 \x8d Some string"}]'
683
683
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 )" )
685
685
self .execute ("INSERT INTO test VALUES (1, 'A value')" )
686
686
self .execute ("COMMIT" )
687
- self .execute ("ALTER TABLE test MODIFY COLUMN data VARCHAR(50) CHARACTER SET utf8mb4" )
688
687
self .execute_with_args ("INSERT INTO test (id, data) VALUES (%s, %s)" , (2 , problematic_unicode_string ))
689
688
self .execute ("COMMIT" )
690
689
690
+ # Initialize with ignore_decode_errors=False
691
691
self .stream = BinLogStreamReader (
692
692
self .database ,
693
693
server_id = 1024 ,
694
694
only_events = (WriteRowsEvent ,),
695
695
ignore_decode_errors = False
696
696
)
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' )
704
703
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
705
709
self .stream = BinLogStreamReader (
706
710
self .database ,
707
711
server_id = 1024 ,
@@ -710,8 +714,14 @@ def test_ignore_decode_errors(self):
710
714
)
711
715
self .stream .fetchone ()
712
716
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"}]' )
715
725
716
726
def test_drop_column (self ):
717
727
self .stream .close ()
0 commit comments