googleapis / python-datastore

Apache License 2.0
80 stars 44 forks source link

samples: Add snippets for sum and avg #480

Closed jlara310 closed 1 year ago

jlara310 commented 1 year ago

Add sample snippets for sum and avg aggregation queries.

Two of these snippets depend on the following index:

indexes:

I added samples/snippets/index.yaml to track the indexes required for the samples.

Fixes #479 🦕

snippet-bot[bot] commented 1 year ago

Here is the summary of changes.

You are about to add 5 region tags. - [samples/snippets/snippets.py:234](https://github.com/jlara310/python-datastore/blob/805723c207c10e7fb6ab545971f3e4788f1ae1ed/samples/snippets/snippets.py#L234), tag `datastore_sum_aggregation_query_on_kind` - [samples/snippets/snippets.py:260](https://github.com/jlara310/python-datastore/blob/805723c207c10e7fb6ab545971f3e4788f1ae1ed/samples/snippets/snippets.py#L260), tag `datastore_sum_aggregation_query_with_filters` - [samples/snippets/snippets.py:295](https://github.com/jlara310/python-datastore/blob/805723c207c10e7fb6ab545971f3e4788f1ae1ed/samples/snippets/snippets.py#L295), tag `datastore_avg_aggregation_query_on_kind` - [samples/snippets/snippets.py:321](https://github.com/jlara310/python-datastore/blob/805723c207c10e7fb6ab545971f3e4788f1ae1ed/samples/snippets/snippets.py#L321), tag `datastore_avg_aggregation_query_with_filters` - [samples/snippets/snippets.py:356](https://github.com/jlara310/python-datastore/blob/805723c207c10e7fb6ab545971f3e4788f1ae1ed/samples/snippets/snippets.py#L356), tag `datastore_multiple_aggregation_in_structured_query`

This comment is generated by snippet-bot. If you find problems with this result, please file an issue at: https://github.com/googleapis/repo-automation-bots/issues. To update this comment, add snippet-bot:force-run label or use the checkbox below:

daniel-sanche commented 1 year ago

We discussed this offline, but please see if you can modify the index as part of the test setup

Let me know if you need any help with this

jlara310 commented 1 year ago

@daniel-sanche

I added a test fixture to set up indexes but it's getting a permission error:

google.api_core.exceptions.PermissionDenied: 403 The caller does not have permission
daniel-sanche commented 1 year ago

@daniel-sanche

I added a test fixture to set up indexes but it's getting a permission error:

google.api_core.exceptions.PermissionDenied: 403 The caller does not have permission

Hmm, that's strange, because the service account has IndexAdmin permissions. And I can also see an audit log that looks like the operation was successful, and I see an index that looks like the one you created on datastore image

I wonder what would happen if you removed the result() from admin_client.create_index(request).result()? It looks like it uses a separate rpc to get the operation status, I wonder if it's possible that is the one that is raising 403?

Or you could try catching the error to silence it for now, to see if the index you need was created properly

jlara310 commented 1 year ago

You're right. The IndexAdmin role does not have permissions for operations. Removed the code that tries to wait for the operation.

jlara310 commented 1 year ago

Only the Python 3.10 test failed. Perhaps the IndexAdmin role is missing for that project?

daniel-sanche commented 1 year ago

thanks, I opened a request to add the missing permission to that project

daniel-sanche commented 1 year ago

@jlara310 Ok, the permissions have been added and the tests are now passing!