Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Fixes

- Recursion in `openDatabase` when using `SentrySqfliteDatabaseFactory` ([#3231](https://github.com/getsentry/sentry-dart/pull/3231))

## 9.7.0-beta.2

### Features
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:meta/meta.dart';
import 'package:sentry/sentry.dart';
import 'package:sqflite/sqflite.dart';
import 'package:sqflite/sqflite.dart' as sqflite show databaseFactory;
// ignore: implementation_imports
import 'package:sqflite_common/src/factory_mixin.dart';
// ignore: implementation_imports
Expand Down Expand Up @@ -35,11 +36,11 @@ class SentrySqfliteDatabaseFactory with SqfliteDatabaseFactoryMixin {
SentrySqfliteDatabaseFactory({
DatabaseFactory? databaseFactory,
@internal Hub? hub,
}) : _databaseFactory = databaseFactory,
}) : _databaseFactory = databaseFactory ?? sqflite.databaseFactory,
_hub = hub ?? HubAdapter();

final Hub _hub;
final DatabaseFactory? _databaseFactory;
final DatabaseFactory _databaseFactory;

@override
Future<T> invokeMethod<T>(String method, [Object? arguments]) =>
Expand All @@ -50,7 +51,7 @@ class SentrySqfliteDatabaseFactory with SqfliteDatabaseFactoryMixin {
String path, {
OpenDatabaseOptions? options,
}) async {
final databaseFactory = _databaseFactory ?? this;
final databaseFactory = _databaseFactory;

// ignore: invalid_use_of_internal_member
if (!_hub.options.isTracingEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,32 @@ void main() {
});
});

group('openDatabase without delegate', () {
late Fixture fixture;

setUp(() {
fixture = Fixture();

when(fixture.hub.options).thenReturn(fixture.options);
when(fixture.hub.scope).thenReturn(fixture.scope);
when(fixture.hub.getSpan()).thenReturn(fixture.tracer);

// using ffi for testing on vm
sqfliteFfiInit();
databaseFactory = databaseFactoryFfi;
});

test('does not recurse when calling instance openDatabase', () async {
final wrapper = SentrySqfliteDatabaseFactory(hub: fixture.hub);

final db = await wrapper.openDatabase(inMemoryDatabasePath);

expect(db is SentryDatabase, true);

await db.close();
});
});

tearDown(() {
databaseFactory = sqfliteDatabaseFactoryDefault;
});
Expand Down
Loading