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-emulator: datastore-mode] Unexpected response from nested query like a profile.name = foo #6999

Open
p1ass opened this issue Apr 15, 2024 · 1 comment

Comments

@p1ass
Copy link

p1ass commented Apr 15, 2024

[REQUIRED] Environment info

firebase-tools: v13.7.2

Platform: macOS

gcloud: v470.0.0

cloud-datastore-emulator: v2.3.1
cloud-firestore-emulator: v1.19.4

[REQUIRED] Test case

package.json

{
  "version": "1.0.0",
  "description": "",
  "main": "lib/index.js",
  "scripts": {
    "build": "tsc",
    "start": "DATASTORE_EMULATOR_HOST=127.0.0.1:8080 node lib/index.js",
    "start:emulator:old": "gcloud --project=dummy-project-id beta emulators datastore start --use-firestore-in-datastore-mode --host-port=127.0.0.1:8080",
    "start:emulator:new": "gcloud emulators firestore start --database-mode=datastore-mode --host-port=127.0.0.1:8080"
  },
  "devDependencies": {
    "@google-cloud/datastore": "^8.6.0",
    "typescript": "^5.4.3"
  }
}

src/index.ts

import {Datastore, PropertyFilter} from "@google-cloud/datastore";

const datastore = new Datastore({
  projectId: "dummy-project-id",
});

const KIND_USER = 'User'

type User = {
  email: string
  profile : {
    name: string
  }
}

export async function getUsersByName(name: string) {
  const query = datastore.createQuery(KIND_USER).filter(new PropertyFilter('profile.name','=',name));
  const [entities] = await datastore.runQuery(query);
  return entities
}



export async function addUser(data: User) {
  const key = datastore.key(KIND_USER);
  const entity = {
    key: key,
    data,
  };
  await datastore.save(entity);
}

async function main() {
  await addUser({email: "foo@example.com", profile: {name: "Awesome Name"}})

  const users = await getUsersByName("Awesome Name");
  console.log(users);
}

main();

tsconfig.json

{
  "compilerOptions": {
    "target": "es2016",
    "module": "commonjs",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true,
    "outDir": "lib"
  },
  "include": ["src"],
  "exclude": []
}

[REQUIRED] Steps to reproduce

Datastore Emulator (Old)

npm install
npm run start:emulator:old
$ npm run build && npm run start

> build
> tsc

> start
> DATASTORE_EMULATOR_HOST=127.0.0.1:8080 node lib/index.js

[
  {
    profile: { name: 'Awesome Name' },
    email: 'foo@example.com',
    [Symbol(KEY)]: Key { namespace: undefined, id: '1', kind: 'User', path: [Getter] }
  }
]

Firestore Emulator (New, Preview)

npm install
npm run start:emulator:new
$ npm run build && npm run start

> build
> tsc

> start
> DATASTORE_EMULATOR_HOST=127.0.0.1:8080 node lib/index.js

[]

[REQUIRED] Expected behavior

[
  {
    profile: { name: 'Awesome Name' },
    email: 'foo@example.com',
    [Symbol(KEY)]: Key { namespace: undefined, id: '1', kind: 'User', path: [Getter] }
  }
]

[REQUIRED] Actual behavior

The result filtered by profile.name should include the user, but not when using the new emulator.

[]
@p1ass p1ass changed the title [firestore-emulator: datastore-mode] Unexpected response from nested query [firestore-emulator: datastore-mode] Unexpected response from nested query like a profile.name = foo Apr 15, 2024
@aalej
Copy link
Contributor

aalej commented Apr 15, 2024

Hey @p1ass , thanks for reaching out and for filing a detailed report. This is appreciated! I was able to reproduce the issue using the information provided. I’ll raise this to our engineering team and see what we can do here.

@harshyyy21 harshyyy21 self-assigned this Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants