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

Storing an Entity as an indexed property value always fails #529

Closed
dhermes opened this issue Jan 9, 2015 · 8 comments
Closed

Storing an Entity as an indexed property value always fails #529

dhermes opened this issue Jan 9, 2015 · 8 comments
Assignees
Labels
api: datastore Issues related to the Datastore API.

Comments

@dhermes
Copy link
Contributor

dhermes commented Jan 9, 2015

From the spec:

If a value is itself an entity, it cannot have indexed set to true.

This means when the entity_value is added we should set indexed to False on the property. (This is currently not easy, see #403, #404 and #512.)

Or maybe we should just document that users need to add a property name to exclude_from_indexes if that property is an Entity.


To replicate:

>>> import os
>>> from gcloud import datastore
>>> from gcloud.datastore.entity import Entity
>>> from gcloud.datastore.key import Key
>>> 
>>> datastore.set_default_connection()
>>> dataset_id = os.getenv('GCLOUD_TESTS_DATASET_ID')
>>> datastore.set_default_dataset_id(dataset_id)
>>> 
>>> e = Entity(key=Key('Foo', 1))
>>> e2 = Entity(key=Key('Foo', 2))
>>> e['bar'] = e2
>>> e.save()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "gcloud/datastore/entity.py", line 144, in save
    exclude_from_indexes=self.exclude_from_indexes)
  File "gcloud/datastore/connection.py", line 495, in save_entity
    result = self.commit(dataset_id, mutation)
  File "gcloud/datastore/connection.py", line 376, in commit
    datastore_pb.CommitResponse)
  File "gcloud/datastore/connection.py", line 100, in _rpc
    data=request_pb.SerializeToString())
  File "gcloud/datastore/connection.py", line 77, in _request
    raise six.moves.http_client.HTTPException(message)
httplib.HTTPException: Request failed with status code 400.
                       Error was: Entity value is indexed.

and notice it doesn't fail if the property is correctly unindexed:

>>> e = Entity(key=Key('Foo', 1), exclude_from_indexes=('bar',))
>>> e['bar'] = e2
>>> e.save()
>>> e.key.delete()
@dhermes dhermes added the api: datastore Issues related to the Datastore API. label Jan 9, 2015
@dhermes
Copy link
Contributor Author

dhermes commented Jan 9, 2015

Note, also setting

e['foo'] = 'a' * 501

will cause a failure

Request failed with status code 400.
Error was: Indexed blob value has more than permitted 500 bytes.

since the spec states

When indexed is true, stringValue is limited to 500 characters and the blob value
is limited to 500 bytes.

Maybe we are better off just documenting this and letting the users worry about it.

I think in terms of code complexity, we are better off doing nothing (beyond documentation) and waiting for user feedback.

@tseaver
Copy link
Contributor

tseaver commented Jan 12, 2015

Is there stuff in the datastore API docs that describes these limitations in detail? I'd rather just point to them, than try to write such docs ourselves.

@dhermes
Copy link
Contributor Author

dhermes commented Jan 12, 2015

@proppy Is there somewhere under https://cloud.google.com/datastore/docs/... that surface the comments from the proto spec?

@proppy
Copy link
Contributor

proppy commented Jan 12, 2015

@dhermes In the API section there is a link to the .proto in the github repo for the current release.
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/v1beta2-rev1-2.1.0/proto/datastore_v1.proto

@dhermes
Copy link
Contributor Author

dhermes commented Jan 12, 2015

@proppy Sorry I was unclear.

I was asking if the user-facing docs actually have sections to match the "docs" from the spec. For example

When indexed is true, stringValue is limited to 500 characters and the blob value
is limited to 500 bytes.

is in the spec, but is it documented anywhere else? Same for

If a value is itself an entity, it cannot have indexed set to true.

and other useful information from the spec.

@proppy
Copy link
Contributor

proppy commented Jan 12, 2015

Sorry if I was unclear too :) At first there was a proto API reference that was duplicating the proto comment, but it was removed in a favor of a link to the file in the github repo.

The JSON API Reference source the doc from the same proto, so in theory https://cloud.google.com/datastore/docs/apis/v1beta2/entity should feature the same comment for the stringValue property description. But for some reason those seems to be missing from this page.

@dhermes
Copy link
Contributor Author

dhermes commented Jan 12, 2015

Thanks. So in general we can point people to those docs for failure cases.

@dhermes
Copy link
Contributor Author

dhermes commented Jan 14, 2015

Deferring this to #532

@dhermes dhermes closed this as completed Jan 14, 2015
@jgeewax jgeewax modified the milestone: Datastore Stable Jan 30, 2015
parthea pushed a commit that referenced this issue Aug 15, 2023
* fix: Add async context manager return types

chore: Mock return_value should not populate oneof message fields

chore: Support snippet generation for services that only support REST transport

chore: Update gapic-generator-python to v1.11.0
PiperOrigin-RevId: 545430278

Source-Link: googleapis/googleapis@601b532

Source-Link: googleapis/googleapis-gen@b3f18d0
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYjNmMThkMGY2NTYwYTg1NTAyMmZkMDU4ODY1ZTc2MjA0NzlkN2FmOSJ9

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
parthea pushed a commit that referenced this issue Sep 22, 2023
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
parthea pushed a commit that referenced this issue Oct 21, 2023
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
parthea pushed a commit that referenced this issue Oct 21, 2023
)

Source-Link: googleapis/synthtool@0c7b033
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:08e34975760f002746b1d8c86fdc90660be45945ee6d9db914d1508acdf9a547

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
parthea added a commit that referenced this issue Oct 21, 2023
* feat: remove workaround

* regenerate client with workarounds removed

---------

Co-authored-by: Anthonios Partheniou <partheniou@google.com>
parthea pushed a commit that referenced this issue Oct 22, 2023
)

Source-Link: googleapis/synthtool@d6103f4
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:39f0f3f2be02ef036e297e376fe3b6256775576da8a6ccb1d5eeb80f4c8bf8fb

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the Datastore API.
Projects
None yet
Development

No branches or pull requests

4 participants