Flutterfire: [firebase_core , cloud_firestore] hashCode of DocumentReference seems broken

Created on 20 Aug 2020  ·  5Comments  ·  Source: FirebaseExtended/flutterfire

Describe the bug

2524 was closed by #2942, but added test cases don't partially cover intention of #2524.

In this senario,

DocumentReference docRef = firestore.collection('foo').doc('bar');
// Same firestore instance and same path
DocumentReference docRef2 = firestore.collection('foo').doc('bar');

With #2524 this succeeds, but currently it fails.

// Same instance
expect(docRef.hashCode == docRef.hashCode, isTrue);
// Different instance but same firestore instance and same path
expect(docRef.hashCode == docRef2.hashCode, isTrue);

Expected behavior

In the test case above, both of them should succeed.
I tried to fix at #3263.

Flutter doctor
Run flutter doctor and paste the output below:

❯ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel dev, 1.21.0-9.0.pre, on Mac OS X 10.15.6 19G73, locale en-JP)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 11.6)
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.0)
[✓] IntelliJ IDEA Community Edition (version 2019.1.3)
[✓] VS Code (version 1.48.0)
[✓] Connected device (6 available)

@Ehesp Could you consider this?

cloud_firestore

Most helpful comment

Same issue with the new firestore version:

Code:

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final ref1 = FirebaseFirestore.instance.collection('test').doc('doc1');
    final ref2 = FirebaseFirestore.instance.collection('test').doc('doc1');
    return MaterialApp(
      title: 'Firebase',
      home: Scaffold(
        body: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text("ref1: ${ref1.hashCode}"),
            Text("ref2: ${ref2.hashCode}"),
          ],
        ),
      ),
    );
  }
}

Output
image

All 5 comments

@mono0926 If firestore and firestoreSecondary are pointing to two different Firestore databases from two different projects then we would expect them to not be equal even if the paths of the references are the same. I think #2942 is correct. If #2524 is not resolved then we should reopen it. @mono0926 are you still seeing #2524 issue?

@kroikie
Thanks for the respose!
Yes, you are right, I partially misunderstood but I suspect there is still a problem.
I'll correct the issue and response soon.

@kroikie

I partially misunderstood, so I rewrote the issue, and I found the cause and tried to fix it at #3263.

I'm also experiencing this problem as it broke functionality in our app after upgrading to cloud_firestore 0.14. @mono0926 is spot on the underlying problem in FirebaseOptions.

I can imagine there are many apps out there breaking because of this, equality is a pretty common operation after all.

Same issue with the new firestore version:

Code:

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final ref1 = FirebaseFirestore.instance.collection('test').doc('doc1');
    final ref2 = FirebaseFirestore.instance.collection('test').doc('doc1');
    return MaterialApp(
      title: 'Firebase',
      home: Scaffold(
        body: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text("ref1: ${ref1.hashCode}"),
            Text("ref2: ${ref2.hashCode}"),
          ],
        ),
      ),
    );
  }
}

Output
image

Was this page helpful?
0 / 5 - 0 ratings