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

Entity creation type safety #819

Closed
pcostell opened this issue Apr 11, 2015 · 6 comments · Fixed by #888
Closed

Entity creation type safety #819

pcostell opened this issue Apr 11, 2015 · 6 comments · Fixed by #888
Assignees
Labels
api: datastore Issues related to the Datastore API.

Comments

@pcostell
Copy link
Contributor

Right now, if you create an entity like:

e = datastore.entity.Entity(key, ('data'))

The unindexable properties will be 'd', 'a', or 't'. Obviously in this case the user meant to specify:

e = datastore.entity.Entity(key, ('data',))

Perhaps the Entity constructor should verify that exclude_from_indexes is a list or tuple.

Here is the discussion where the user ran into this: https://groups.google.com/forum/#!topic/gcd-discuss/rqwF8CRdTAY

@pcostell pcostell added the api: datastore Issues related to the Datastore API. label Apr 11, 2015
@dhermes
Copy link
Contributor

dhermes commented Apr 11, 2015

Thanks for the pointer to the discussion! I'm torn on this.

Getting bit by passing in a string as an iterable is somewhat of a rite of passage in Python (as we saw, the user misunderstood the ('data') syntax as being a way to create a tuple). By whitelisting list and tuple it rules out people that might want to pass in their own custom iterables. On the flipside, this is a really straightforward property so maybe we'd just suggest they pass in list(custom_iterable).

@pcostell
Copy link
Contributor Author

I'm not partial either way, just wanted to pass it on.

@dhermes
Copy link
Contributor

dhermes commented Apr 12, 2015

Got it. Thanks.

@tseaver WDYT?

@pcostell
Copy link
Contributor Author

One extra thought --

Maybe it should be an error if you provide properties to exclude_from_indexes that you never actually store in the entity. It could indicate bad application logic.

@dhermes
Copy link
Contributor

dhermes commented Apr 13, 2015

When do we decide the Entity is "final"?

@pcostell
Copy link
Contributor Author

In this instance probably on put.

@dhermes dhermes modified the milestone: Datastore Stable Apr 13, 2015
@dhermes dhermes self-assigned this May 20, 2015
dhermes added a commit to dhermes/google-cloud-python that referenced this issue May 20, 2015
dhermes added a commit to dhermes/google-cloud-python that referenced this issue May 27, 2015
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

Successfully merging a pull request may close this issue.

2 participants