I am trying to use google cloud datastore
kind query to get a list of kind names as demoed in the Kind queries,
query = client.query(kind='__kind__')
query.keys_only()
kinds = [entity.key.id_or_name for entity in query.fetch()]
but the code generates some built-in kind names, e.g.
['_AE_DatastoreAdmin_Operation', '_GAE_MR_TaskPayload',
'__Stat_Kind_IsRootEntity__', '__Stat_Kind_NotRootEntity__',
'__Stat_Kind__', '__Stat_PropertyName_Kind__',
'__Stat_PropertyType_Kind__', '__Stat_PropertyType_PropertyName_Kind__',
'__Stat_PropertyType__', '__Stat_Total__']
I am wondering how to remove these built-in kind names and only retain user created kind names.
Those appear to be kinds of real entities created on the local development server/emulator - they can actually be seen in the Datastore Viewer. For example the
__Stat_*
ones are created when the datastoreGenerate Stats
action is performed on the local development server.These entities do not exist in the project's live cloud datastore (or they are stored elsewhere).
With a simple naming rule for the application's entity kinds - to not start with the
_
character - you could obtain thekinds
list like this:Depending on the
kinds
use, another option - safer IMHO from coding perspective - might be to always check the kind names against an explicit expected list (for example when wiping out allkinds
entities):