aws-amplify / amplify-flutter

A declarative library with an easy-to-use interface for building Flutter applications on AWS.
https://docs.amplify.aws
Apache License 2.0
1.33k stars 247 forks source link

DataStore query throws Exception with empty QueryPagination on Android #842

Closed Jordan-Nelson closed 2 years ago

Jordan-Nelson commented 3 years ago

Describe the bug QueryPagination() has no required arguments. page is optional and limit defaults to 100. However, the query will fail on Android if no value page is supplied. page should either be required or default to 0. On iOS, the first page is returned if no page is supplied.

To Reproduce Below is an integration test which will throw an exception on Android.

group('pagination', () {
  var models = List.generate(1000, (i) => Blog(name: 'blog $i'));
  setUp(() async {
    await configureDataStore();
    // clear data before each test
    await clearDataStore();
    for (var model in models) {
      await Amplify.DataStore.save(model);
    }
  });
  testWidgets('should return the models for the given page and limit',
      (WidgetTester tester) async {
    var blogs = await Amplify.DataStore.query(Blog.classType,
        pagination: QueryPagination());
  });
});

Expected behavior page should either be required or default to 0. If page is not required, the query should not throw an exception without a supplied value.

Screenshots If applicable, add screenshots to help explain your problem.

Platform Amplify Flutter current supports iOS and Android. This issue is reproducible in (check all that apply): [x] Android [] iOS

Jordan-Nelson commented 3 years ago

Given that iOS defaults to page 0, page should probably have a default value of 0.

HuiSF commented 3 years ago

Given that iOS defaults to page 0

Is this default value set within amplify-flutter iOS implementation or amplify-ios please?

Jordan-Nelson commented 3 years ago

@HuiSF I will have to check. This was just an observation based on testing. I have not looked into where it is set.

cshfang commented 2 years ago

Should be fixed by #1533