Skip to content

Commit

Permalink
Backport stream fix
Browse files Browse the repository at this point in the history
  • Loading branch information
simolus3 committed Nov 26, 2023
1 parent ce554a0 commit ac1c57f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
5 changes: 5 additions & 0 deletions drift/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.13.2

- Fix a race condition causing query streams to not emit new data around some
transaction setups.

## 2.13.1

- Fix a bug when running batches over serialized communication channels.
Expand Down
1 change: 1 addition & 0 deletions drift/lib/src/runtime/executor/stream_queries.dart
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ class QueryStream {
for (final op in _runningOperations) {
op.cancel();
}
_runningOperations.clear();
}

Future<void> fetchAndEmitData() async {
Expand Down
2 changes: 1 addition & 1 deletion drift/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: drift
description: Drift is a reactive library to store relational data in Dart and Flutter applications.
version: 2.13.1
version: 2.13.2
repository: https://github.com/simolus3/drift
homepage: https://drift.simonbinder.eu/
issue_tracker: https://github.com/simolus3/drift/issues
Expand Down
30 changes: 30 additions & 0 deletions drift/test/integration_tests/regress_2744_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:drift/drift.dart';
import 'package:test/test.dart';

import '../generated/todos.dart';
import '../test_utils/test_utils.dart';

void main() {
test('updates after transaction', () async {
// Regression test for https://github.com/simolus3/drift/issues/2744
final db = TodoDb(testInMemoryDatabase());
final categories = db.categories.all().watch();

expect(categories, emits(isEmpty));
await db.categories
.insertOne(CategoriesCompanion.insert(description: 'desc1'));
expect(categories, emits(hasLength(1)));

await db.categories.deleteAll();
await db.batch((batch) {
batch.insert(
db.categories, CategoriesCompanion.insert(description: 'desc2'));
});

expect(
categories,
emits([
isA<Category>().having((e) => e.description, 'description', 'desc2')
]));
});
}
2 changes: 1 addition & 1 deletion examples/migrations_example/lib/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Database extends _$Database {
@override
int get schemaVersion => latestSchemaVersion;

Database(DatabaseConnection connection) : super(connection);
Database(super.connection);

@override
MigrationStrategy get migration {
Expand Down

0 comments on commit ac1c57f

Please sign in to comment.