Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

TransactionResult doesn't allow abort on non dynamic data #71

Open
natebot13 opened this issue Sep 19, 2020 · 1 comment
Open

TransactionResult doesn't allow abort on non dynamic data #71

natebot13 opened this issue Sep 19, 2020 · 1 comment

Comments

@natebot13
Copy link

await database.ref('queue').transaction<Map<String, dynamic>>(
  (currentData) {
    print(currentData);
    if (currentData.length.isOdd) {
      print('aborting!');
      return TransactionResult.abort;
    }
    print('hand waving done');
    return TransactionResult.success(currentData);
  },
);

I'm running into a compile issue with this code. The transaction.abort line gives an error saying: The return type 'TransactionResult<dynamic>' isn't a 'TransactionResult<Map<String, dynamic>>', as required by the closure's context.

Am I allowed to specify the transaction type?

@pulyaevskiy
Copy link
Owner

This looks like a bug in the admin interop package:

https://github.com/pulyaevskiy/firebase-admin-interop/blob/b958afb5cdf893ce76b2d71c67ee4b023e5087d4/lib/src/database.dart#L560-L568

class TransactionResult<T> {
  TransactionResult._(this.aborted, this.data);
  final bool aborted;
  final T data;


  static TransactionResult abort = new TransactionResult._(true, null);
  static TransactionResult<T> success<T>(T data) =>
      new TransactionResult._(false, data);
}

The abort field should really be closer to

static TransactionResult<T> abort = new TransactionResult<T>._(true, null);

Though I'm not sure if this is a valid use of generics. Might need to be changed into a static method the same way as success.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants