-
Notifications
You must be signed in to change notification settings - Fork 212
"Cannot parse Firebase url" on snapshot reference access when using RTDB via firebase functions. #746
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
Comments
cc @samtstern (because I've reported other emulator related issues to you) |
@filipesilva what version of |
The repro (https://github.com/filipesilva/firebase-emulator-parse-url) is using [email protected]. Everything there is the latest as of today, I believe. |
@filipesilva sorry I should have clicked into that |
Ok a few things here:
|
It looks like
This is a |
Ok so I added some logging and
The {
"eventType": "google.firebase.database.ref.create",
"params": {
"postId": "-MCviHJhohdsNE5uAJWZ"
},
"domain": "localhost",
"resource": {
"service": "firebaseio.com",
"name": "projects/_/instances/emulator-test-1/refs/posts/-MCviHJhohdsNE5uAJWZ"
},
"timestamp": "2020-07-23T12:49:58.150Z",
"eventId": "5/3OSuz1TP5pWvc/Lt0o9RDcN2M=",
"authType": "ADMIN"
} So the port is lost ... gonna have to think about this one. |
@filipesilva question for you: when you're running inside the Functions emulator and you also have the RTDB emulator running, but you do this:
Do you still expect So I'm trying to decide if the actual bug is that your |
@samtstern I don't quite care about setting I do care about setting I also care about setting Attempting to set it with no
Attempting to set it with
So in my concrete work example it does not seem possible to just go with the defaults. I must set |
@filipesilva thanks for clarifying all of that ... there's a lot going on here and I'll have to think of the best way to solve it. |
@samtstern heya, did you have time to think about what a resolution for this looks like? |
@filipesilva thanks for bumping this issue! I took another look today and think I found a really simple fix: Here are the functions I am using: const functions = require('firebase-functions');
const admin = require('firebase-admin');
const instance = "fir-dumpster-secondary";
admin.initializeApp({
databaseURL: `https://${instance}.firebaseio.com/`,
credential: admin.credential.applicationDefault()
});
exports.posts = functions.https.onRequest(async (request, response) => {
const db = admin.database();
const ref = await db.ref('posts').push({
date: new Date().toISOString()
});
response.send(`Added: ${ref}`);
});
exports.postsPushHandler = functions.database
.instance(instance)
.ref('/posts/{postId}')
.onCreate(snapshot => {
console.log("onCreate:", snapshot.ref.toString());
return true;
}); And here are the logs I get:
In the Emulator UI it all seems wired up correctly: Would you mind testing this for me? You can check out my branch of this repo and then run |
@samtstern thanks for getting back to me so quickly! I tested your branch build on https://github.com/filipesilva/firebase-emulator-parse-url and can confirm I no longer get the URL error, and that the write correctly goes through. I think that fixes it! |
@samtstern today I was integrating your changes into our codebase, and I found a follow up problem with the fix you submitted. I've updated the original repository with the most recent firebase versions and code to repro this problem in https://github.com/filipesilva/firebase-emulator-parse-url/commit/979d5c65808b15a423ee29aff0c33748c3c9a9eb. The repro steps are still the same:
This time the output is:
This logging comes from the updated handler:
Attempting to access the database for the initialised admin app results in an error. There is no error if It seems that using the snapshot ref initialises a database for the same url, but with a different URL. Can this issue be reopened, or should I open a new issue? |
@filipesilva sure let's reopen this issue. So from that commit you sent it looks like there's a regression in one of the recent SDK updates. Could be |
Hi @samtstern! I tried going back to the original package versions for everything but firebase-functions in https://github.com/filipesilva/firebase-emulator-parse-url/commit/9ea2e64603b4f4d123fb248cce2cff012e964f95. The new problem still repros so I think it's related to firebase-functions. I'm not even sure it's a regression though. I didn't test this originally with your fix because it required a larger time investment in updating our codebase, so it's possible that it was never working either. |
[REQUIRED] Describe your environment
[REQUIRED] Describe the problem
It's currently not possible to access the data snapshot reference when using RTDB via firebase functions.
I believe this is due to the check in https://github.com/firebase/firebase-js-sdk/blob/6af4c27743372ba531e8ce3d046ae2f81e8f5be1/packages/database/src/core/util/libs/parser.ts#L83-L91
That piece of code checks that
parsedUrl.domain
islocalhost
, but it seems to beemulator-test-1.localhost
instead.Steps to reproduce:
You should see the following error log in the console:
Relevant Code:
The text was updated successfully, but these errors were encountered: