Skip to content

snapshot.ref with multiple realtime databases points to the wrong one with Emulators #3961

Closed
firebase/firebase-functions
#1339
@KantiKuijk

Description

@KantiKuijk

[REQUIRED] Environment info

firebase-tools: 9.23.3

Platform: macOS

[REQUIRED] Test case

exports.testDelete = functions.database
  .instance("rdb-2")
  .ref("/foo/bar1")
  .onDelete(async (snapshot, context) => {
    await snapshot.ref.set(0);
  });

exports.testUpdate = functions.database
  .instance("rdb-2")
  .ref("/foo/bar1")
  .onUpdate(async (change, context) => {
    await change.before.ref.parent.child("bar3").set(789);
    await change.after.ref.set(789);
  });

exports.testCreate = functions.database
  .instance("rdb-2")
  .ref("/foo/bar1")
  .onCreate(async (snapshot, context) => {
    await snapshot.ref.parent.child("bar2").set(456);
  });

[REQUIRED] Steps to reproduce

  1. copy-paste the code above and start the firebase emulators
  2. in the firebase emulator console, navigate to the rdb-2 realtime database instance
  3. add a node at foo/bar1 giving it a value of let's say 123
  4. change the value to let's say 456
  5. delete the node

[REQUIRED] Expected behavior

After step 3, I'd expect there a sibling bar2 to appear having the value 456.
After step 4, I'd expect there a sibling bar3 to appear having the value 789, and having the value itself change to 789 (which would then trigger the function once more).
After step 5, I'd expect the deleted node to reappear with the value 0.

[REQUIRED] Actual behavior

After step 3, a node at foo/bar2 with the value 456 appears in the default database instance, instead of the rdb-2 instance.
After step 4, a node at foo/bar3 with the value 789 and a node at foo/bar1 with the value 789 appears in the default database instance, instead of the rdb-2 instance.
After step 5, the node foo/bar1 changes to a value 0 in the default database instance, instead of the rdb-2 instance.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions