Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Firestore string value is empty #895

Closed
SebastienDevQuebec opened this issue Dec 12, 2020 · 21 comments
Closed

Firestore string value is empty #895

SebastienDevQuebec opened this issue Dec 12, 2020 · 21 comments
Assignees
Labels
api: firestore needs-attention Need Googler's attention

Comments

@SebastienDevQuebec
Copy link

SebastienDevQuebec commented Dec 12, 2020

[REQUIRED] Please fill in the following fields:

  • Unity editor version: 2020.1.16f1
  • Firebase Unity SDK version: 7.0.1
  • Source you installed the SDK: Unity Package Manager
  • Problematic Firebase Component: Firestore
  • Other Firebase Components in use: Analytics, Crashanalytic, Auth & Function
  • Additional SDKs you are using: Admob
  • Platform you are using the Unity editor on: Windows
  • Platform you are targeting: Android
  • Scripting Runtime: IL2CPP

[REQUIRED] Please describe the issue here:

Not sure if it can be reproduced.

Here is a link to the detailed issue on StackOverflow:
https://stackoverflow.com/questions/65174003/unity-firestore-weird-bug#comment115384693_65174003

In summary,
I listen to a document, and with the value I do things. it works great in the editor but when compiled on my mobile the value is always = to "" (nothing).

@SebastienDevQuebec
Copy link
Author

Anyone?

@wilhuff
Copy link

wilhuff commented Dec 14, 2020

Sorry for the trouble with this. I'm currently working on reproducing your findings and will update when I have an idea of what's going wrong.

@wilhuff wilhuff self-assigned this Dec 14, 2020
@SebastienDevQuebec
Copy link
Author

Ok thank you, I am gonna try downgrading the Firebase plugin

@SebastienDevQuebec
Copy link
Author

Sorry for the trouble with this. I'm currently working on reproducing your findings and will update when I have an idea of what's going wrong.

In case you want to know, I just tested it... and it works perfectly in 6.16.1

@wilhuff
Copy link

wilhuff commented Dec 15, 2020

That's good to know. I'm still working on reproducing this in a way that I can debug what's going on.

@wilhuff
Copy link

wilhuff commented Dec 15, 2020

I've been unable to reproduce the empty value you're describing.

All the values I read and write come through without issue. I've tried several variations based on your stackoverflow post:

  • Using GetSnapshotAsync vs Listen
  • Starting/restarting more than one listener for the same document
  • Examining values directly vs calling ToString on them

In all cases I'm unable to observe the empty value that you're seeing in your logs.

I've been reproducing using an emulated Pixel 2 running Android 7.0. Do you observe this error when running on an Android emulator? If you don't see this on the emulator but do observe it on a physical device, which device is it?

Another tack to try is to look to see if this is somehow specific to your application. Do you see the same kind of empty values if you add logging to the Firestore Unity quickstart?

@wilhuff wilhuff added the needs-info Need information for the developer label Dec 15, 2020
@SebastienDevQuebec
Copy link
Author

SebastienDevQuebec commented Dec 16, 2020

My phone is a Samsung S9+
Don't have time to test it on an emulator

I have reproduced the empty value on a new project:

  • Youtube play "LaGrange (1999 remaster)" very important!
  • Open Unity Create a new empty project
  • Add MyRegistery Google LLC and Download Firestore only.
  • Create UI_TchatManager.cs
  • Create FirebaseDependencies.cs
  • Insert both scripts in an empty game object
  • Link Firebase
  • Add data to your Firestore... (At this point I just realize that when you "Add field" on the firebase console example: M_1043923842: "ANDBLABLA" it works perfectly, the only data that glitch is the one Cloud functions fill up)

here is a screenshot in yellow I fill up manually, the rest is a "Cloud Function" function...
Capture
screenshot of the result: I restart my app 10x and the manual data is still there and perfect. let me remind you that the other data the one generated by the cloud function is ok the first time the app open, but after the restart value is null.
Screenshot_20201215-222317_ThinkFast

I am stopping here it is late I have to work tomorrow at 5h30 it's almost 23h00 hiiiii need my 8hours.

I think the Cloud function has something to do whit the problem.

UI_TchatManager.cs

using Firebase.Firestore;
using System.Collections.Generic;
using UnityEngine;

public class UI_TchatManager : MonoBehaviour
{
    // Default Instance
    public static UI_TchatManager Default = null;

    private ListenerRegistration SocialDocumentListener = null;

    private void Awake()
    {
        // Set Instance
        if (Default == null)
        {
            Default = this;
        }
        else
        {
            // Destroy Class
            Destroy(this.gameObject);
            return;
        }

        DontDestroyOnLoad(this);

        Debug.Log("<b>Tchat:</b> Awake");
    }

    // Get Tchat Message
    public void AttachListener(int iLobbyID)
    {
        if (FirebaseDependencies.Default.bIsFirebaseAvailable)
        {
            FirebaseFirestore db = FirebaseFirestore.DefaultInstance;

            DocumentReference SocialDocument = db.Document($"Social/Lobby 1");

            // Attach Listener
            SocialDocumentListener = null;

            SocialDocumentListener = SocialDocument.Listen(snapshot => {
                Debug.Log("Attached!");
                // Snapshot
                Dictionary<string, object> TchatDictionary = snapshot.ToDictionary();

                foreach (KeyValuePair<string, object> x in TchatDictionary)
                {
                    Debug.Log($"<color=purple>Social/Lobby 1 -> Key:{x.Key} / Value:{x.Value} ({x.Value.ToString().Length})</color>");
                }
            });
        }
        else
        {
            Debug.LogWarning($"Firebase is not available");
        }
    }
}

FirebaseDependencies.cs

using Firebase;
using Firebase.Firestore;
using System;
using System.Collections;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.SceneManagement;

public class FirebaseDependencies : MonoBehaviour
{
    // Set Default Instance
    public static FirebaseDependencies Default = null;

    public bool bIsFirebaseAvailable = false;

    private void Awake()
    {
        // Set Instance
        if (Default == null)
        {
            Default = this;
        }
        else
        {
            Destroy(this.gameObject);
            return;
        }
        DontDestroyOnLoad(this);

        Debug.Log("<b>Firebase Dependencies:</b> Awake");

        StartCoroutine("CheckFirebaseDependencies");
    }

    // Check Status
    private IEnumerator CheckFirebaseDependencies()
    {
        var TaskCheckDependencies = FirebaseApp.CheckAndFixDependenciesAsync();

        yield return new WaitUntil(() => TaskCheckDependencies.IsCompleted);

        if (TaskCheckDependencies.Result == Firebase.DependencyStatus.Available)
        {
            Debug.Log($"<b>Firebase Dependencies:</b> {TaskCheckDependencies.Result}");
            bIsFirebaseAvailable = true;
        }
        else
        {
            Debug.LogWarning(TaskCheckDependencies.Result);
            bIsFirebaseAvailable = false;
        }
    }

    // Check Error
    private bool CheckError(AggregateException exception, int firebaseExceptionCode)
    {
        Firebase.FirebaseException fbEx = null;
        foreach (Exception e in exception.Flatten().InnerExceptions)
        {
            fbEx = e as Firebase.FirebaseException;
            if (fbEx != null)
                break;
        }

        if (fbEx != null)
        {
            if (fbEx.ErrorCode == firebaseExceptionCode)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        return false;
    }
}

@google-oss-bot google-oss-bot added needs-attention Need Googler's attention and removed needs-info Need information for the developer labels Dec 16, 2020
@wilhuff
Copy link

wilhuff commented Dec 16, 2020

I've followed your steps (though I had to change the code because nothing was actually calling AttachListener) but I can see this working via a local emulator and also on a Samsung Galaxy S9+ (G965F) and also see the values coming through:

12-16 10:41:35.600: I/Unity(25687): (Filename: ./Runtime/Export/Debug.bindings.h Line: 45)
12-16 10:41:35.969: I/Unity(25687): Attached!
12-16 10:41:35.969: I/Unity(25687):  
12-16 10:41:35.969: I/Unity(25687): (Filename: ./Runtime/Export/Debug.bindings.h Line: 45)
12-16 10:41:36.055: I/Unity(25687): <color=purple>Social/Lobby 1 -> Key:bar / Value:42 (2)</color>
12-16 10:41:36.055: I/Unity(25687):  
12-16 10:41:36.055: I/Unity(25687): (Filename: ./Runtime/Export/Debug.bindings.h Line: 45)
12-16 10:41:36.055: I/Unity(25687): <color=purple>Social/Lobby 1 -> Key:foo / Value:hello world (11)</color>

I've also written a small node.js program that writes to Socal/Lobby 1 and I can observe the values it writes from your app running on Android.

If you can put together an example that reproduces this issue I'll happily look into it further, but at this point I suspect there must be a bug somewhere in your application, possibly in the function that's writing values to this document.

@wilhuff wilhuff added needs-info Need information for the developer and removed needs-attention Need Googler's attention labels Dec 16, 2020
@SebastienDevQuebec
Copy link
Author

SebastienDevQuebec commented Dec 16, 2020

Anyway, I just gonna let that go.... everything works fine in firebase 6.16.1!

I am 100% sure it is not my app.

  1. on Firestore 7.0.1 it doesn't work -> but on Firestore 6.16.1 it works.
  2. and everything works on the editor when it is packaged on android it bug.
  3. There a new posts on this forum that look like my problem StringIndexOutOfBoundsException on firestore API with unicode character #900

Thank you, and see you next bug. bye bye

@google-oss-bot google-oss-bot added needs-attention Need Googler's attention and removed needs-info Need information for the developer labels Dec 16, 2020
@wilhuff
Copy link

wilhuff commented Dec 16, 2020

I'm genuinely interested in finding and fixing this issue, but can't do anything without being able to observe the issue myself.

You mentioned that adding data via the console works, but the values don't show when added via a function. Is it possible there are differences in the kind of data you're adding in these cases? For example, is the function setting more or slightly different data? Could you send the complete contents of a document that's not working?

@SebastienDevQuebec
Copy link
Author

SebastienDevQuebec commented Dec 16, 2020

I only have one document in social called Lobby 1 all the data I add manually works but all the cloud function generated data does not work (psst: only on android maybe ios too did not test ios) on the unity engine everything works perfectly.

M_1DQOIZEPSebTHEking:"ANDCA1213181337211000Bein oui" Generated by cloud function will not work.
but the same M_1DQOIZEPSebTHEking:"ANDCA1213181337211000Bein oui" enter manually in Firestore will work

Capture1

async function InitSendMessageV2(data, context)
{
  return new Promise(resolve => {
    setTimeout(async () => {
      // Firebase Reference
      const database = admin.firestore();
      // Date Stamp
      var date = new Date();
      var dateStr = 
      ("00" + (date.getMonth() + 1)).slice(-2) +
      ("00" + date.getDate()).slice(-2) +
      ("00" + date.getHours()).slice(-2) +
      ("00" + date.getMinutes()).slice(-2) +
      ("00" + date.getSeconds()).slice(-2);
      // 
      var LoginRow = {}; 
      LoginRow["M_" + IdGenerator(8) + data.Name] = data.Platform + data.CountryCode + dateStr + (("000000" + (data.Color * 1000)).slice(-6)) + data.Message;
      // Get Lobby Document
      const GetLobbyDocument = await database.collection('Social').doc("Lobby " + data.LobbyID).set((LoginRow), {merge: true});
      resolve(true);
    });
  });
}

Just to recap:
1- Happen only when build on Android.
2- The Key is ok but the value is empty "" only when it's a string... the numbers are working correctly.
3- Data generated by Cloud functions does not work but data added manually works
4- My app has a collection call Leaderboard and data are created by cloud functions too but everything works perfectly and value are string too. see screen shoot below
5- Firestore 6.16.1 work but 7.0.1 does not

Capture2

@wilhuff
Copy link

wilhuff commented Dec 16, 2020

Is it possible that the strings that are failing contain unicode characters? If that's the case, this is the same issue as #900.

@SebastienDevQuebec
Copy link
Author

You can see for yourself in my last post, all failed except 2 of them that I manually enter

@SebastienDevQuebec
Copy link
Author

To reproduce the bug make sure to use the -> Package Manager -> Firestore 7.0.1

@wilhuff
Copy link

wilhuff commented Dec 17, 2020

I'm definitely using Firestore 7.0.1.

I've adapted the cloud function code you provided to write data that looks very similar to what you've shown:

{
  "M_K95dMZB6yhhB58xS3GBASebTHEking": "ANDCA1216222233211000Saliut",
  "M_iZW425FCYi5eqXNhUze7SebTHEking": "ANDCA1216222233211000salut",
  "M_f8XXjaMGvIgFIOVastO9SebTHEking": "ANDCA1216222233211000hrhf",
  "M_zMp94xX5Wn0tzX4SLctFSebTHEking": "ANDCA1216222233211000gdf",
  "M_5D6jmNULKB3LUKh2ax5jPlayer39463": "ANDCA1216222232029000you taking to you",
  "M_ht2UtsxU8IusBXxbx7FUSebTHEking": "ANDCA1216222233211000Salut",
  "M_XJkTPVlbwAeASol5ZTxZSebTHEking": "ANDCA1216222233211000lok",
  "M_5SBZ5BFRSiouZlcdx9LiSebTHEking": "ANDCA1216222233211000lol",
  "M_OcWYWFwwUcZfw9nMF3YuPlayer39463": "ANDCA1216222233029000lala",
  "M_sztPY7ZRMBMREXwfuzdXSebTHEking": "ANDCA1216222232211000loo",
  "M_0w2z4AmcjR95QyXhUl5RSebTHEking": "ANDCA1216222232211000Bein oui"
}

Using this data the values still come through.

Even after bumping the number of entries in the document to 100 the values still come through.

If I add a non-ASCII character, this does cause the value to end up empty--this is the effect of issue #900. If this were happening to you you'd see a StringIndexOutOfBoundsException in the logs. However, #900 only has its effect if the string contains non-ASCII characters. Do you see any exceptions in logs (with adb logcat)?

@wilhuff wilhuff added needs-info Need information for the developer and removed needs-attention Need Googler's attention new New issue. labels Dec 17, 2020
@tamotamago
Copy link

I've been facing the same issue.
It happens on only Android devices. It works fine on iPhone and Unity editor.

@wilhuff
Copy link

wilhuff commented Dec 21, 2020

@tamotamago Firestore in release 7.0.1 contained a bug in the way it handled Unicode strings that resulted in empty string values (#900). We've released 7.0.2 which fixes that. It's not clear if this issue is the same.

I've been unable to reproduce the issue described here--string values being empty only when changed via Cloud Function--so it's not clear if these are the same issue. Are you seeing StringIndexOutOfBoundsException exceptions in the Android log?

@SebastienDevQuebec
Copy link
Author

I can't see the 7.0.2 on unity Package manager yet... I will test it as soon as it comes out.

@google-oss-bot google-oss-bot added needs-attention Need Googler's attention and removed needs-info Need information for the developer labels Dec 21, 2020
@tamotamago
Copy link

@wilhuff 7.0.2 works well for me. Thanks!

I've been unable to reproduce the issue described here--string values being empty only when changed via Cloud Function--so it's not clear if these are the same issue. Are you seeing StringIndexOutOfBoundsException exceptions in the Android log?

In my case, Japanese and German characters were emptied. English characters are fetched correctly. And I did not see any exceptions on Android Logcat.

@schmidt-sebastian
Copy link

@tamotamago Thank you for confirming that 7.0.2 fixed your issue. I will close this issue based on this assessment.

@schmidt-sebastian
Copy link

@SebastienDevQuebec - We will re-open this issue if you are still blocked.

@firebase firebase locked and limited conversation to collaborators Jan 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api: firestore needs-attention Need Googler's attention
Projects
None yet
Development

No branches or pull requests

5 participants