You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
returns an updated handle to the same object (for list comprehension/chaining), and
does some sanity checking on the added properties?
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.
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).
Activity
tseaver commentedon 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 thegcloud-datastoreAPI needs: all the "special" stuff is down in the attributes (_datasetand_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:
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 thesort()orappend()methods for lists, for instance).dhermes commentedon Nov 26, 2014
@ebbixby I am tracking issues like this in #336.
I'm closing this and adding your remarks to that thread.
__getitem__, not__getattr__, so there is no conflict.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!
Merge pull request googleapis#389 from dtorres-sf/master
chore(main): release 2.0.3 (#389)
chore: detect samples tests in nested directories (#389)
chore(deps): update dependency google-api-python-client to v2.65.0 (#389
chore: fix prerelease_deps nox session [autoapprove] (#389)
chore(deps): update dependency pytest to v7.1.3 (#389)
chore(python): Enable size-label bot (#389)
chore(deps): update dependency google-cloud-storage to v2.7.0 (#389)
2 remaining items
chore: [autoapprove] update readme_gen.py to include autoescape True (#…
chore(deps): update all dependencies (#389)
chore(deps): update dependency google-cloud-translate to v3.7.3 (#389)
chore(python): upgrade gcp-releasetool in .kokoro [autoapprove] (#389)
fix: remove libcst as a required dependency (#389)
fix: remove libcst as a required dependency (#389)
doc: unify layout with Google client libraries (#389)
Test and impl for stripping whitespace off option tokens (#389)
chore(deps): update dependency google-cloud-datastore to v2.11.0 (#389)
chore(main): release 1.6.2 (#389)
samples: Delete samples/snippets directory (#389)
chore(main): release 2.6.0 (#389)
django: fix dropping a column with an index
chore(python): simplify nox steps in CONTRIBUTING.rst (#389)
fix: retrieve keyword arguments for docstrings (#389)