Skip to content

Commit f371bfc

Browse files
authored
Reference to primaryDatabase is always non-null. (dart-lang#9476)
1 parent 121446a commit f371bfc

7 files changed

Lines changed: 23 additions & 23 deletions

File tree

app/lib/database/database.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void registerPrimaryDatabase(PrimaryDatabase database) =>
3131
ss.register(#_primaryDatabase, database);
3232

3333
/// The active primary database service.
34-
PrimaryDatabase? get primaryDatabase => _lookupPrimaryDatabase();
34+
PrimaryDatabase get primaryDatabase => _lookupPrimaryDatabase()!;
3535

3636
PrimaryDatabase? _lookupPrimaryDatabase() =>
3737
ss.lookup(#_primaryDatabase) as PrimaryDatabase?;

app/lib/frontend/handlers/pubapi.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ class PubApi {
465465
Future<Response> debug(Request request) async => debugResponse({
466466
'package': packageDebugStats(),
467467
'search': searchDebugStats(),
468-
'database': await primaryDatabase?.debug(),
468+
'database': await primaryDatabase.debug(),
469469
});
470470

471471
@EndPoint.get('/packages.json')

app/lib/service/services.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ Future<R> _withPubServices<R>(FutureOr<R> Function() fn) async {
327327
registerTaskBackend(
328328
TaskBackend(
329329
dbService,
330-
primaryDatabase!,
330+
primaryDatabase,
331331
storageService.bucket(activeConfiguration.taskResultBucketName!),
332332
),
333333
);

app/test/database/postgresql_ci_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ void main() {
4343
testWithProfile(
4444
'registered database scope',
4545
fn: () async {
46-
final name = await primaryDatabase!.verifyConnection();
46+
final name = await primaryDatabase.verifyConnection();
4747
expect(name, contains('fake_pub_'));
4848
},
4949
);
5050

5151
testWithProfile(
5252
'typed schema access',
5353
fn: () async {
54-
await primaryDatabase!.withRetry((db) async {
54+
await primaryDatabase.withRetry((db) async {
5555
await db.tasks
5656
.insert(
5757
runtimeVersion: runtimeVersion.asExpr,

app/test/database/retry_zone_test.dart

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void main() {
1616
'retry returns value',
1717
fn: () async {
1818
int count = 0;
19-
final rs = await primaryDatabase!.withRetry((db) async {
19+
final rs = await primaryDatabase.withRetry((db) async {
2020
count++;
2121
return 2;
2222
});
@@ -31,7 +31,7 @@ void main() {
3131
int count = 0;
3232

3333
await expectLater(
34-
() async => await primaryDatabase!.withRetry((db) async {
34+
() async => await primaryDatabase.withRetry((db) async {
3535
count++;
3636
throw NotFoundException('');
3737
}),
@@ -47,7 +47,7 @@ void main() {
4747
int count = 0;
4848

4949
await expectLater(
50-
() async => await primaryDatabase!.withRetry((db) async {
50+
() async => await primaryDatabase.withRetry((db) async {
5151
count++;
5252
await db.insertBadData();
5353
}),
@@ -63,8 +63,8 @@ void main() {
6363
int count = 0;
6464

6565
await expectLater(
66-
() async => await primaryDatabase!.withRetry((db) async {
67-
await primaryDatabase!.withRetry((db) async {
66+
() async => await primaryDatabase.withRetry((db) async {
67+
await primaryDatabase.withRetry((db) async {
6868
count++;
6969
await db.insertBadData();
7070
});
@@ -81,8 +81,8 @@ void main() {
8181
int count = 0;
8282

8383
await expectLater(
84-
() async => await primaryDatabase!.withRetry((db) async {
85-
await primaryDatabase!.transactWithRetry((db) async {
84+
() async => await primaryDatabase.withRetry((db) async {
85+
await primaryDatabase.transactWithRetry((db) async {
8686
count++;
8787
await db.insertBadData();
8888
});
@@ -99,7 +99,7 @@ void main() {
9999
'transactWithRetry returns value',
100100
fn: () async {
101101
int count = 0;
102-
final rs = await primaryDatabase!.transactWithRetry((db) async {
102+
final rs = await primaryDatabase.transactWithRetry((db) async {
103103
count++;
104104
return 2;
105105
});
@@ -114,7 +114,7 @@ void main() {
114114
int count = 0;
115115

116116
await expectLater(
117-
() async => await primaryDatabase!.transactWithRetry((db) async {
117+
() async => await primaryDatabase.transactWithRetry((db) async {
118118
count++;
119119
throw NotFoundException('');
120120
}),
@@ -130,7 +130,7 @@ void main() {
130130
int count = 0;
131131

132132
await expectLater(
133-
() async => await primaryDatabase!.transactWithRetry((db) async {
133+
() async => await primaryDatabase.transactWithRetry((db) async {
134134
count++;
135135
await db.insertBadData();
136136
}),
@@ -146,8 +146,8 @@ void main() {
146146
int count = 0;
147147

148148
await expectLater(
149-
() async => await primaryDatabase!.transactWithRetry((db) async {
150-
await primaryDatabase!.transactWithRetry((db) async {
149+
() async => await primaryDatabase.transactWithRetry((db) async {
150+
await primaryDatabase.transactWithRetry((db) async {
151151
count++;
152152
await db.insertBadData();
153153
});
@@ -164,8 +164,8 @@ void main() {
164164
int count = 0;
165165

166166
await expectLater(
167-
() async => await primaryDatabase!.transactWithRetry((db) async {
168-
await primaryDatabase!.withRetry((db) async {
167+
() async => await primaryDatabase.transactWithRetry((db) async {
168+
await primaryDatabase.withRetry((db) async {
169169
count++;
170170
await db.insertBadData();
171171
});

app/test/fake/tool/local_state_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void main() {
2525
processJobsWithFakeRunners: true,
2626
fn: () async {
2727
// Read current task from the database.
28-
final taskBefore = await primaryDatabase!.withRetry(
28+
final taskBefore = await primaryDatabase.withRetry(
2929
(db) => db.tasks.byKey(runtimeVersion, 'sample').fetch(),
3030
);
3131
expect(taskBefore, isNotNull);
@@ -34,7 +34,7 @@ void main() {
3434
final tempDir = await Directory.systemTemp.createTemp('local_state_');
3535
final dataFile = '${tempDir.path}/state.jsonl';
3636
try {
37-
final state1 = LocalServerState(database: primaryDatabase!);
37+
final state1 = LocalServerState(database: primaryDatabase);
3838
await state1.save(dataFile);
3939

4040
// Verify the file was created and is non-empty.

app/test/task/task_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ void main() {
726726
await taskBackend.runOneLoopCycle();
727727

728728
// verify token is now aborted
729-
final ps = await primaryDatabase!.withRetry(
729+
final ps = await primaryDatabase.withRetry(
730730
(schema) => schema.taskLookupOrNull('neon'),
731731
);
732732
expect(ps!.state.versions[v.version]?.secretToken, isNull);
@@ -771,7 +771,7 @@ void main() {
771771
],
772772
),
773773
);
774-
final ps = await primaryDatabase!.withRetry(
774+
final ps = await primaryDatabase.withRetry(
775775
(schema) => schema.taskLookupOrNull('neon'),
776776
);
777777
expect(

0 commit comments

Comments
 (0)