Skip to content
This repository has been archived by the owner on May 13, 2023. It is now read-only.

stream returns invalid response #87

Closed
phamhieu opened this issue Jan 14, 2022 · 5 comments
Closed

stream returns invalid response #87

phamhieu opened this issue Jan 14, 2022 · 5 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@phamhieu
Copy link
Member

phamhieu commented Jan 14, 2022

(Note: Before upgrade to 0.2.12, the stream worked correctly.)

I found the stream has a bug which cause an error: stream replace the correct row and cause error.

When I insert a row into a table, it shows the following error message:
"The method 'toDouble' was called on null.
Receiver: null
Tried calling: toDouble()"

In fact, I checked the data row I insert into the table is correct as follow:

{projectId: 22-038, itemNumber: 7, itemName: test7, unit: M, unitPrice: 1500.0, contractQuantity: 500.0, contractAmount: 750000.0, remark: , cumulativeCompletedQuantity: 0.0}

which is correct data.

After the insert action is finished, the stream response and shows the data as follow:

{contractAmount: null, contractQuantity: null, cumulativeCompletedQuantity: null, id: 87, itemName: test7, itemNumber: 7, projectId: 22-038, remark: , unit: M, unitPrice: null}

at the same time I get the error message I mentioned above. (
"The method 'toDouble' was called on null.
Receiver: null
Tried calling: toDouble()" )

This is because the stream replace my correct row with wrong row which change my original data to "null".

Then, I check the database and found the correct row {projectId: 22-038, itemNumber: 7, itemName: test7, unit: M, unitPrice: 1500.0, contractQuantity: 500.0, contractAmount: 750000.0, remark: , cumulativeCompletedQuantity: 0.0} still insert into the database successfully. But my App become red screen and shows the error message which should not happen!!

It's so strange!!

Before I upgrade to supabase-dart 0.2.12 with new stream usage by primary-key, the stream worked very good and 100% correct for the same code to insert data to database.

How can I resolve this problem??


class MyItem {
// other code of this classs 

MyItem.fromSnapshot(Map<String, dynamic> snapshot)
      : id = snapshot['id'],
        projectId = snapshot['projectId'],
        itemNumber = snapshot['itemNumber'],
        itemName = snapshot['itemName'],
        unit = snapshot['unit'],
        unitPrice = snapshot['unitPrice'].toDouble(),
        contractQuantity = snapshot['contractQuantity'].toDouble(),
        contractAmount = snapshot['contractAmount'].toDouble(),
        remark = snapshot['remark'],
        cumulativeCompletedQuantity = snapshot['cumulativeCompletedQuantity'].toDouble();

// other code of this class ...
}

List<MyItem> getMyItemsFromQuery(List<Map<String, dynamic>> snapshot) {
    _items = []; // Type: MyItem
    
    for (final doc in snapshot) {
      // **Todo: check Supabase-dart 0.2.12 stream error: stream replace the correct row with null on some columns!!**
      
      _items.add(MyItem.fromSnapshot(doc));
    }

    return _items;
  }

// here is the StreamBuilder code sample:
StreamBuilder<List<Map<String, dynamic>>>(
      stream: _supabase.from('myItems:projectId=eq.$projectId').stream(['id']).order('id', ascending: true).execute(),
      builder: (context, snapshot) {
        if (snapshot.hasError) {
          return Center(
            child: Text(snapshot.error.toString()),
          );
        }

        // if (!snapshot.hasData || snapshot.connectionState == ConnectionState.waiting) {
        if (!snapshot.hasData) {
          return const Center(child: CupertinoActivityIndicator());
        }

      
        List<MyItem> items = getMyItemsFromQuery(snapshot.requireData);

related to #82

@phamhieu phamhieu added the bug Something isn't working label Jan 14, 2022
@phamhieu phamhieu added the help wanted Extra attention is needed label Jan 14, 2022
@Vinzent03
Copy link
Contributor

I don't think my changes in #82 are the reason, because I didn't change anything on insert. I guess the bug is in 0.2.11.

@JasonChiu-dev
Copy link

JasonChiu-dev commented Jan 14, 2022

  1. The stream bug happened since yesterday. And my supabase package's setup on pubspec.yaml file was: supabase: ^0.2.10 at the beginning.

  2. On Thu, 13 Jan at 2:06 PM, I reported an error to Supabase tech team:
    Hi, It worked ok about one hour ago, but I can not log into Supabase now and shows error message: "LateInitializationError: Field 'changedAccessToken' has not been initialized.". How can I solve this problem?? Need help. Jason Chiu

  3. On Thu, 13 Jan at 3:53 PM, the Supabase tech team reply:
    The error has been resolved by this PR Fixed changedAccessToken never initialized when changing account #84.. Can you checkout the latest supabase-dart.
    ​Please let us know if the problem persists. Thank you.
    Best,
    Hieu

  4. Then I upgrade the setup of pubspec.yaml to: supabase: ^0.2.12

  5. I can login Supabase correctly, but the stream bug(the stream replace my correct row with wrong row which change my original data to "null".) show up. That means the correct row data really insert into the database table successfully, but the stream fetch the data and change many columns' data with null.

  6. All the story happened in these two days.

For your information.

@JasonChiu-dev
Copy link

5. That means the correct row data really insert into the database table successfully, but the stream fetch the data and change many columns' data with null.

The insert action is correct. It means the correct row data really insert into the database table successfully, but the stream fetch the data and change many columns' data with null. This is the real problem.

@phamhieu
Copy link
Member Author

Hi @JasonChiu-dev supabase-dart: ^0.2.13 is deployed. Let me know if it works for you.

@JasonChiu-dev
Copy link

Hi @phamhieu It works correctly now. Thank you so much for your inform and help.

@bdlukaa bdlukaa closed this as completed Jan 17, 2022
@supabase supabase locked as resolved and limited conversation to collaborators Jan 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants