Skip to content

Commit 9b706c1

Browse files
ichikobuenaflor
andauthored
fix: abortTransaction does not call provided execute function when parent span is null (#3062)
* Call execute when parent span is null * Add tests to check calling execute with parent span or not * Rewrite tests that tests the actual user scenario * Append this PR to CHANGELOG.md * Update CHANGELOG.md --------- Co-authored-by: Giancarlo Buenaflor <[email protected]> Co-authored-by: Giancarlo Buenaflor <[email protected]>
1 parent 79f6b41 commit 9b706c1

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Span ids not re-generating for headers created from scope ([#3051](https://github.com/getsentry/sentry-dart/pull/3051))
88
- `ScreenshotIntegration` not being added for web ([#3055](https://github.com/getsentry/sentry-dart/pull/3055))
99
- `PropagationContext` not being set when `Scope` is cloned resulting in different trace ids when using `withScope` ([#3069](https://github.com/getsentry/sentry-dart/pull/3069))
10+
- Drift transaction rollback not executed when parent span is null ([#3062](https://github.com/getsentry/sentry-dart/pull/3062))
1011

1112
### Enhancements
1213

drift/lib/src/sentry_span_helper.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class SentrySpanHelper {
151151
'Active Sentry transaction does not exist, could not finish span for Drift operation: Abort Transaction',
152152
logger: loggerName,
153153
);
154-
return Future<T>.value();
154+
return execute();
155155
}
156156

157157
try {

drift/test/sentry_drift_test.dart

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,52 @@ void main() {
603603
);
604604
});
605605

606+
test(
607+
'transaction is rolled back within Sentry transaction, added aborted span',
608+
() async {
609+
final sut = fixture.getSut();
610+
final db = AppDatabase(NativeDatabase.memory().interceptWith(sut));
611+
612+
final tx = _startTransaction();
613+
614+
// pre-condition: table empty
615+
expect(await db.select(db.todoItems).get(), isEmpty);
616+
617+
// run a transaction that is forced to fail -> should be rolled back
618+
await expectLater(
619+
() => db.transaction(() async {
620+
await _insertRow(db, withError: true);
621+
}),
622+
throwsA(isA<Exception>()),
623+
);
624+
625+
final abortedSpans =
626+
tx.children.where((child) => child.status == SpanStatus.aborted());
627+
expect(abortedSpans.length, 1);
628+
629+
// if rollback happened the row must be absent
630+
expect(await db.select(db.todoItems).get(), isEmpty);
631+
});
632+
633+
test('transaction is rolled back without Sentry transaction', () async {
634+
final sut = fixture.getSut();
635+
final db = AppDatabase(NativeDatabase.memory().interceptWith(sut));
636+
637+
// pre-condition: table empty
638+
expect(await db.select(db.todoItems).get(), isEmpty);
639+
640+
// run a transaction that is forced to fail -> should be rolled back
641+
await expectLater(
642+
() => db.transaction(() async {
643+
await _insertRow(db, withError: true);
644+
}),
645+
throwsA(isA<Exception>()),
646+
);
647+
648+
// if rollback happened the row must be absent
649+
expect(await db.select(db.todoItems).get(), isEmpty);
650+
});
651+
606652
test('batch does not add span for failed operations', () async {
607653
final sut = fixture.getSut();
608654
final db = AppDatabase(NativeDatabase.memory().interceptWith(sut));

0 commit comments

Comments
 (0)