#coding:utf-8 # # id: bugs.core_5843 # title: Wrong handling of failures of TRANSACTION START trigger # decription: # Confirmed wrong behaviour on 3.0.4.32972, 4.0.0.955. # Works fine on: # FB30SS, build 3.0.4.32988: OK, 1.328s. # FB40SS, build 4.0.0.1008: OK, 1.500s # (checked both on SS and CS). # # tracker_id: CORE-5843 # min_versions: ['3.0.4'] # versions: 3.0.4 # qmid: None import pytest from firebird.qa import db_factory, isql_act, Action # version: 3.0.4 # resources: None substitutions_1 = [('line[:]{0,1}[\\s]+[\\d]+.*', 'line'), ('transaction[\\s]+[\\d]+[\\s]+aborted', 'transaction aborted'), ('tx=[\\d]+', 'tx='), ('TX_ID[\\s]+[\\d]+', 'TX_ID'), ('exception[\\s]+[\\d]+.*', 'exception')] init_script_1 = """ --set echo on; set bail on; create or alter trigger tx_rollback on transaction rollback as begin end; create or alter trigger tx_start on transaction start as begin end; create or alter trigger tx_commit on transaction commit as begin end; create or alter view v_mon as select t.mon$transaction_id as tx_id ,t.mon$state as tx_state --,a.mon$remote_process att_process --,a.mon$attachment_name as att_name --,a.mon$system_flag as att_sysflag --,a.mon$user as att_user from mon$transactions t join mon$attachments a using (mon$attachment_id) where mon$attachment_id = current_connection ; commit; set term ^; create or alter exception ex_tra_start 'transaction @1 aborted' ^ create or alter procedure tx_trig_log(msg varchar(255)) as declare s varchar(255); begin s = rdb$get_context('USER_SESSION', 'tx_trig_log'); if (s <> '') then begin s = s || ASCII_CHAR(10) || trim(msg) || ', current tx=' || current_transaction; rdb$set_context('USER_SESSION', 'tx_trig_log', :s); end end ^ create or alter trigger tx_start on transaction start as declare s varchar(255); begin execute procedure tx_trig_log('trigger on transaction start '); if (rdb$get_context('USER_SESSION', 'tx_abort') = 1) then begin execute procedure tx_trig_log('exception on tx start '); rdb$set_context('USER_SESSION', 'tx_abort', 0); exception ex_tra_start using (current_transaction); end end ^ create or alter trigger tx_commit on transaction commit as declare s varchar(255); begin execute procedure tx_trig_log('trigger on commit'); end ^ create or alter trigger tx_rollback on transaction rollback as declare s varchar(255); begin execute procedure tx_trig_log('trigger on rollback'); end ^ create or alter procedure sp_use_atx as begin rdb$set_context('USER_SESSION', 'tx_abort', 1); execute procedure tx_trig_log('sp_use_atx, point_a'); in autonomous transaction do execute procedure tx_trig_log('sp_use_atx, point_b'); end ^ set term ;^ commit; """ db_1 = db_factory(sql_dialect=3, init=init_script_1) test_script_1 = """ set autoddl off; set list on; commit; select 'test_1, point-1' as msg, v.* from rdb$database cross join v_mon v; set term ^; execute block as declare c int; begin c = rdb$set_context('USER_SESSION', 'tx_abort', 1); -- flag to raise error on next tx start end ^ set term ^; commit; select 'test_1, point-2' as msg, v.* from rdb$database cross join v_mon v; -- it start transaction commit; set count on; select 'test_1, point-3' as msg, v.* from rdb$database cross join v_mon v; set count off; rollback; ------------------------------------------------------------- --connect '$(DSN)' user 'SYSDBA' password 'masterkey'; set term ^; execute block as declare c int; begin c = rdb$set_context('USER_SESSION', 'tx_trig_log', ascii_char(10) || 'start: tx=' || current_transaction ); -- start logging end ^ set term ^; commit; select 'test2, point-a' as msg, v.* from rdb$database cross join v_mon v; execute procedure sp_use_atx; /* Statement failed, SQLSTATE = HY000 exception 3 -EX_TRA_START -transaction 692 aborted -At trigger 'TX_START' line: 10, col: 5 At procedure 'sp_use_atx' line: 4, col: 3 */ select rdb$get_context('USER_SESSION', 'tx_trig_log') from rdb$database; """ act_1 = isql_act('db_1', test_script_1, substitutions=substitutions_1) expected_stdout_1 = """ MSG test_1, point-1 TX_ID 22 TX_STATE 1 MSG test_1, point-3 TX_ID 25 TX_STATE 1 Records affected: 1 MSG test2, point-a TX_ID 28 TX_STATE 1 RDB$GET_CONTEXT start: tx=26 trigger on commit, current tx=26 trigger on transaction start, current tx=28 sp_use_atx, point_a, current tx=28 trigger on transaction start, current tx=29 exception on tx start, current tx=29 """ expected_stderr_1 = """ Statement failed, SQLSTATE = HY000 exception 1 -EX_TRA_START -transaction 23 aborted -At trigger 'TX_START' line Statement failed, SQLSTATE = HY000 exception 1 -EX_TRA_START -transaction 29 aborted -At trigger 'TX_START' line At procedure 'SP_USE_ATX' line """ @pytest.mark.version('>=3.0.4') def test_1(act_1: Action): act_1.expected_stdout = expected_stdout_1 act_1.expected_stderr = expected_stderr_1 act_1.execute() assert act_1.clean_stderr == act_1.clean_expected_stderr assert act_1.clean_stdout == act_1.clean_expected_stdout