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

list_indexes function returns all indexes in the database, not within a collection #874

Open
fbjorn opened this issue Mar 6, 2024 · 0 comments
Assignees
Labels
api: firestore Issues related to the googleapis/python-firestore API.

Comments

@fbjorn
Copy link

fbjorn commented Mar 6, 2024

Hi,

I'm trying to list composite indexes within a specific collection. Documentation for ListIndexesRequest says:

 parent (str):
            Required. A parent name of the form
            ``projects/{project_id}/databases/{database_id}/collectionGroups/{collection_id}``

And since parent expects a collection id at the end, I assume it should return indexes only within this collection, however it's listing ALL indexes of my database.

I just don't understand if it's an expected behavior, or a bug. If you have a suggestion how I can achieve it, I would appreciate some help.

Environment details

  • OS type and version: MacOS
  • Python version: 3.10.13
  • google-cloud-firestore version: 2.12.0

Code example

from google.cloud.firestore_admin_v1.services.firestore_admin import FirestoreAdminAsyncClient
from google.cloud.firestore_admin_v1 import ListIndexesRequest

async def get_existing_indexes(
    client: FirestoreAdminAsyncClient, path: str
):
    raw_indexes = []
    request = ListIndexesRequest({"parent": f"{path}"})
    operation = await client.list_indexes(request=request)
    async for page in operation.pages:
        raw_indexes.extend(list(page.indexes))
    print([index.name for index in raw_indexes])
    return raw_indexes

If I run this function with path="projects/<>/databases/(default)/collectionGroups/fooBar", I'll get these (project name obfuscated):

    "projects/<>/databases/(default)/collectionGroups/fooBar/indexes/CICAgLjRyYIK",
    "projects/<>/databases/(default)/collectionGroups/fooBar/indexes/CICAgJil0IYK",
    "projects/<>/databases/(default)/collectionGroups/anotherCollection/indexes/CICAgLiI64sK",
    "projects/<>/databases/(default)/collectionGroups/anotherCollection/indexes/CICAgNirtJAK",

As you can see, indexes from another collection are still in the response.

Thanks!

@product-auto-label product-auto-label bot added the api: firestore Issues related to the googleapis/python-firestore API. label Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: firestore Issues related to the googleapis/python-firestore API.
Projects
None yet
Development

No branches or pull requests

2 participants