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

update() override for datastore entities #389

Closed
ghost opened this issue Nov 25, 2014 · 2 comments
Closed

update() override for datastore entities #389

ghost opened this issue Nov 25, 2014 · 2 comments
Labels
api: datastore Issues related to the Datastore API. type: question Request for information or clarification. Not an issue.

Comments

@ghost
Copy link

ghost commented Nov 25, 2014

Writing a code sample I find myself using the dict.update(dict) function quite often to do bulk adds of properties to an entity.

I realized that this can potentially have unsafe behavior (overriding protected fields such as 'id'), and additionally returns None which doesn't seem very pythonic or consistent with past APIs

Would it make sense to override this method within the datastore.entity.Entity class so that it

  1. returns an updated handle to the same object (for list comprehension/chaining), and
  2. does some sanity checking on the added properties?
@tseaver
Copy link
Contributor

tseaver commented Nov 26, 2014

I'm not sure what "special" properties you have in mind, but entity.update(some_dict) won't mess with anything that the gcloud-datastore API needs: all the "special" stuff is down in the attributes (_dataset and _key) and can't be affected by assignment to any of the keys stored by the entity.

Note that the datastore docs for entities do say:

Don't name a property "key." This name is reserved for a special property used to store the
Model key. Though it may work locally, a property named "key" will prevent deployment to
App Engine.

I don't know whether we should be preventing people from using that key. @dhermes, @silvolu opinions?

Given that Python's own dict.update() doesn't return the dict instance, I can't see that making ours return it is "Pythonic": in fact, mutators which return their instance are pretty much un-Pythonic (think about the sort() or append() methods for lists, for instance).

@tseaver tseaver added api: datastore Issues related to the Datastore API. type: question Request for information or clarification. Not an issue. labels Nov 26, 2014
@dhermes
Copy link
Contributor

dhermes commented Nov 26, 2014

@ebbixby I am tracking issues like this in #336.

I'm closing this and adding your remarks to that thread.

  1. RE: chaining, this is (sort of) being discussed in DISCUSSION: Are setter methods which clone and return object type confusing to end-users? #188. It's very JavaScript-y (not Pythonic).
  2. RE: sanity checking, what did you have in mind? Could you comment on Smooth out API surfaces before M1 #336
  3. RE: Protected fields, etc., the actual fields are accessed via __getitem__, not __getattr__, so there is no conflict.
  4. RE: Over-all idea. If you have used ndb, the long term goal is to provide a higher-level API like that and have these classes be the underpinning.

Please re-open if you think #336 is not the right place for your concerns.

UPDATE: I forgot to say, thanks for using our library!

@dhermes dhermes closed this as completed Nov 26, 2014
@jgeewax jgeewax modified the milestone: Datastore Stable Jan 30, 2015
urshala pushed a commit to urshala/google-cloud-python that referenced this issue Jan 17, 2020
Allow for custom JSON Encoder class
parthea pushed a commit that referenced this issue Jun 4, 2023
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
parthea pushed a commit that referenced this issue Jun 4, 2023
Source-Link: googleapis/synthtool@50db768
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:e09366bdf0fd9c8976592988390b24d53583dd9f002d476934da43725adbb978
parthea pushed a commit that referenced this issue Sep 20, 2023
Source-Link: https://togithub.com/googleapis/synthtool/commit/26c7505b2f76981ec1707b851e1595c8c06e90fc
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:f946c75373c2b0040e8e318c5e85d0cf46bc6e61d0a01f3ef94d8de974ac6790
parthea pushed a commit that referenced this issue Sep 22, 2023
Source-Link: googleapis/synthtool@06e8279
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:b3500c053313dc34e07b1632ba9e4e589f4f77036a7cf39e1fe8906811ae0fce
parthea added a commit that referenced this issue Sep 22, 2023
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
…389)

Source-Link: googleapis/synthtool@6b4d5a6
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:f792ee1320e03eda2d13a5281a2989f7ed8a9e50b73ef6da97fac7e1e850b149

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
parthea pushed a commit that referenced this issue Oct 21, 2023
* chore(deps): update all dependencies

* 🦉 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 Oct 21, 2023
Source-Link: https://togithub.com/googleapis/synthtool/commit/5f2a6089f73abf06238fe4310f6a14d6f6d1eed3
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:8555f0e37e6261408f792bfd6635102d2da5ad73f8f09bcb24f25e6afb5fac97
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. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

3 participants