-
Notifications
You must be signed in to change notification settings - Fork 979
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
Database emulator does not support .indexOn #1980
Comments
That's a suuuper old version of |
Heya @bkendall, here's the output:
|
Sorry, now I see that I mixed up the version of |
Also tried with |
Could you please check if the rules are properly loaded in the the emulator by Also, please double check that you're connecting to the same database in your web app as specified to Firebase CLI. On the web app, make sure you're specifying the db name like |
@yuchenshi thanks for giving me all the important things to check. I've made a repro that you can hopefully use to see the same results as I'm seeing, and I think I've also been able to narrow down the nature of the problem. To repro follow these steps:
So it seems that the problem here is actually related to loading the rules file. It isn't loaded initially, but will be loaded on the first save. Any save after the first will fail to load. |
@samtstern Could you please take a look at the repro when you get some time since you are most familiar with the rules (re)loading part? |
Hmm so this is a little strange. When I tried these rules the first time:
I got the error mentioned above:
Then I went back to just read/write=true rules and got success. Then I tried the "bad" rules on more time and also got success:
And now I can't get the same failure as before to repeat at all. I think I need someone to help me investigate where the "no data supplied" error comes from. |
@IanWyszynski could you look into the RTDB emulator source and see why we'd get |
@samstern In the
to check that we're not accidentally sending an empty rules payload? |
@IanWyszynski thanks! Yeah if I replace @filipesilva is this still happening consistently for you? |
@samtstern tried running
I could always reproduce, but sometimes it took two saves to get I wonder if the OS is a factor. I'm on Windows 10 (build 1904184), using node 12.4.0, and yarn 1.21.1. |
Thanks for the logs! We clearly have insufficient logging here so I am adding #1991 to address that at least. It does seem like some of our filesystem reads are failing but I don't know why ... |
@samtstern I updated to
Also tried it with the debug flag:
So it seems that sometimes it works, sometimes it doesn't. |
@filipesilva thanks for being proactive here! This subset of logs shows that there is something flaky going on:
It seems that sometimes when we try to read the file we're getting no content. Maybe that's a result of trying to read too soon after detecting a change? |
In my case I saved the file but didn't change anything about it, so I'd expect an early read to return the same thing. I did some more debugging locally by opening
Then, saving without changes again, I see the following output:
So it seems reading the buffer and converting it to a string is a problem. Not super sure why though. |
I'm reluctant to say that using |
I have the same issue in the emulator. await firebaseTesting.loadDatabaseRules({
databaseName,
rules: fs.readFileSync('../database.rules.json', 'utf8');
}); It still tells me in the emulator that my index is not there.
|
@filipesilva hmmm that's really strange but I do appreciate the investigation and it sounds like we have a possible fix. @abeisgoat do you understand this? |
I took a look at the docs and it seems |
Just tried testing on node and I don't see it at all: const { readFileSync } = require('fs');
const filePath = './file.txt';
async function timeout(ms) {
await new Promise(resolve => setTimeout(() => resolve(), ms));
}
async function test() {
for (let index = 0; index < 10; index++) {
console.log("loop start")
console.log("readFileSync(filePath):", readFileSync(filePath));
console.log("readFileSync(filePath).toString():", readFileSync(filePath).toString());
console.log("readFileSync(filePath, 'utf-8')", readFileSync(filePath, 'utf-8'));
await timeout(1000)
}
}
test();
This really surprises me though. I wonder if some dependency that |
I am going to send a PR to add explicit encoding to all Also I think it should be |
[REQUIRED] Environment info
firebase-tools: 3.3.0
Platform: Windows
[REQUIRED] Test case
I used the official docs example for orderByChild https://firebase.google.com/docs/database/security/indexing-data?authuser=0.
[REQUIRED] Steps to reproduce
Running the code above against a real database shows
stegosaurus: {height: 4, length: 9, weight: 2500}
.Running it against the emulator shows both
stegosaurus: {height: 4, length: 9, weight: 2500}
and a warning:[REQUIRED] Expected behavior
I expected
.indexOn
to be supported, or perhaps for the emulator to mention it was not using the index, or for this limitation to be listed somewhere. Maybe it's already documented but I couldn't find it in the official docs or the issue tracker.[REQUIRED] Actual behavior
The emulator silently ignores the index and the client warns that there is no index.
The text was updated successfully, but these errors were encountered: