SqliteException(1032): attempt to write a readonly database when using amplify_analytics_pinpoint_dart
Description
When initializing and using amplify_analytics_pinpoint_dart in my Flutter app, I receive the following error, even though my app does not directly use Drift or SQLite:
SqliteException(1032): while executing statement, attempt to write a readonly database, attempt to write a readonly database (code 1032)
Stack trace:
package:drift/src/remote/communication.dart 165:20 DriftCommunication.setRequestHandler.<fn> package:drift/src/remote/communication.dart 113:66 DriftCommunication.request package:drift/src/remote/client_impl.dart 101:28 _BaseExecutor._runRequest package:drift/src/remote/client_impl.dart 110:15 _BaseExecutor._intRequest package:drift/src/remote/client_impl.dart 135:12 _BaseExecutor.runInsert package:drift/src/utils/lazy_database.dart 91:17 LazyDatabase.runInsert package:drift/src/runtime/query_builder/statements/insert.dart 74:26 InsertStatement.insert.<fn> package:drift/src/runtime/api/connection_user.dart 171:16 DatabaseConnectionUser.doWhenOpened.<fn> package:drift/src/runtime/query_builder/statements/insert.dart 73:12 InsertStatement.insert package:amplify_analytics_pinpoint_dart/src/impl/analytics_client/event_client/queued_item_store/drift/drift_queued_item_store.dart 57:5 DriftQueuedItemStore.addItem package:amplify_analytics_pinpoint_dart/src/impl/analytics_client/event_client/event_storage_adapter.dart 51:5 EventStorageAdapter.saveEvent package:amplify_analytics_pinpoint_dart/src/impl/analytics_client/event_client/event_client.dart 86:5 EventClient.recordEvent package:amplify_analytics_pinpoint_dart/src/analytics_plugin_impl.dart 145:9 AmplifyAnalyticsPinpointDart.configure.<fn>
Categories
- [x] Analytics
- [ ] API (REST)
- [ ] API (GraphQL)
- [ ] Auth
- [ ] Authenticator
- [ ] DataStore
- [ ] Notifications (Push)
- [ ] Storage
Steps to Reproduce
Record event with this class:
class PinpointTagger implements TaggingDelegate { PinpointTagger._();
factory PinpointTagger() { return _instance; }
static final PinpointTagger instance = PinpointTagger.();
@override
Future
Screenshots
No response
Platforms
- [x] iOS
- [x] Android
- [ ] Web
- [ ] macOS
- [ ] Windows
- [ ] Linux
Flutter Version
3.29.0
Amplify Flutter Version
2.4.1
Deployment Method
Amplify Gen 2
Schema
Hello @DanBeltranuwu, I've attempted to reproduce the issue on Flutter 2.6.3 and was not able to reproduce the issue. I used the following code which I believe is similar enough to your example:
final event = AnalyticsEvent('EventName');
event.customProperties.addStringProperty('Key1', 'Value1');
event.customProperties.addStringProperty('Key2', 'Value2');
event.customProperties.addStringProperty('Key3', 'Value3');
event.customProperties.addStringProperty('Key4', 'Value4');
event.customProperties.addStringProperty('Key5', 'Value5');
await Amplify.Analytics.recordEvent(event: event);
Can you please try the following:
- Update to Amplify Flutter 2.6.3 and retry
- Confirm if this issue occurs in both release/debug
- Are you using isolates, which could result in multiple Analytic instances? (multiple connections to the Event DB could block write access)
Hello @tyllark.
I updated Amplify to 2.6.3 (flutter 3.32.0) and the issue appear again. Occurs in release and debug. I don't see isolates in implementation, so isolates not used.
Hello @DanBeltranuwu, thanks for confirming! Let's rule out any conflicts with other packages by creating a minimal reproducible example:
- Remove all non-Amplify dependencies from your pubspect.yaml
- Run
flutter cleanin your projects root directory - Run
dart pub getin your projects root directory - Remove all your Dart files and add the below main.dart to your project
- Run the test and confirm if the issue persists
dependencies:
amplify_flutter: ^2.6.3
amplify_auth_cognito: ^2.6.3
amplify_push_notifications_pinpoint: ^2.6.3
amplify_analytics_pinpoint: ^2.6.3
main.dart
import 'package:amplify_analytics_pinpoint/amplify_analytics_pinpoint.dart';
import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
import 'package:amplify_flutter/amplify_flutter.dart';
import 'package:flutter/material.dart';
//TODO: import Amplify configuration package
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await _configureAmplify();
runApp(
MaterialApp(
restorationScopeId: 'app',
title: 'Analytics Test',
theme: ThemeData.dark(),
home: HomePage(),
),
);
}
Future<void> _configureAmplify() async {
try {
await Amplify.addPlugins([
AmplifyAuthCognito(),
AmplifyAnalyticsPinpoint(),
]);
await Amplify.configure(amplifyconfig);
safePrint('Success configuring Amplify!');
} on Exception catch (e) {
safePrint('Error configuring Amplify: $e');
}
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Analytics Test'), centerTitle: true),
body: Center(
child: ElevatedButton(
onPressed: _recordEvent,
child: Text('Record Event'),
),
),
);
}
void _recordEvent() async {
try {
final event = AnalyticsEvent('EventName');
event.customProperties.addStringProperty('Key1', 'Value1');
event.customProperties.addStringProperty('Key2', 'Value2');
event.customProperties.addStringProperty('Key3', 'Value3');
event.customProperties.addStringProperty('Key4', 'Value4');
event.customProperties.addStringProperty('Key5', 'Value5');
await Amplify.Analytics.recordEvent(event: event);
safePrint('Event Recorded: ${event.name}');
} catch (e) {
safePrint(e);
}
}
}
Hello @tyllark , I can't execute this test due to the project is a production app currently, so I can't change a lot of things.
Hello @DanBeltranuwu I just wanted to confirm, you are unable run this minimal reproducible example locally as it would generate unwanted analytic events? Or is there a different reason?
Hi @tyllark this is a reason, but also my app have a lot of security validations to make this kind of process a little bit difficult
Hello @DanBeltranuwu, can you create a sandbox amplify environment where you can safely test this minimal reproducible example. If that is also not possible can you please provide a minimal reproducible example code snippet.