Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 8 additions & 8 deletions packages/sqflite/lib/src/sentry_sqflite_database_factory.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:meta/meta.dart';
import 'package:sentry/sentry.dart';
import 'package:sqflite/sqflite.dart';
import 'package:sqflite/sqflite.dart' as sqflite;
// ignore: implementation_imports
import 'package:sqflite_common/src/factory_mixin.dart';
// ignore: implementation_imports
Expand Down Expand Up @@ -33,31 +33,31 @@ class SentrySqfliteDatabaseFactory with SqfliteDatabaseFactoryMixin {
/// final database = await openDatabase('path/to/db');
/// ```
SentrySqfliteDatabaseFactory({
DatabaseFactory? databaseFactory,
sqflite.DatabaseFactory? databaseFactory,
@internal Hub? hub,
}) : _databaseFactory = databaseFactory,
}) : _databaseFactory = databaseFactory ?? sqflite.databaseFactory,
_hub = hub ?? HubAdapter();

final Hub _hub;
final DatabaseFactory? _databaseFactory;
final sqflite.DatabaseFactory _databaseFactory;

@override
Future<T> invokeMethod<T>(String method, [Object? arguments]) =>
impl.invokeMethod(method, arguments);

@override
Future<Database> openDatabase(
Future<sqflite.Database> openDatabase(
String path, {
OpenDatabaseOptions? options,
sqflite.OpenDatabaseOptions? options,
}) async {
final databaseFactory = _databaseFactory ?? this;
final databaseFactory = _databaseFactory;

// ignore: invalid_use_of_internal_member
if (!_hub.options.isTracingEnabled()) {
return databaseFactory.openDatabase(path, options: options);
}

return Future<Database>(() async {
return Future<sqflite.Database>(() async {
final currentSpan = _hub.getSpan();
final description = 'Open DB: $path';
final span = currentSpan?.startChild(
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