core.db.utils

Functions

fix_unindexable_properties(entry, *[, keep_exclusions])

Recursively walk the given Entity and add all properties to the list of unindexed properties if they contain

normalize_key(key)

Normalizes a datastore key (replacing _application with the current one)

normalizeKey(key)

key_helper(in_key, target_kind[, ...])

keyHelper(inKey, targetKind[, additionalAllowedKinds, ...])

is_in_transaction()

IsInTransaction()

get_or_insert(key, **kwargs)

Either creates a new entity with the given key, or returns the existing one.

GetOrInsert(key, **kwargs)

encodeKey(key)

Return the given key encoded as string (mimicking the old str() behaviour of keys)

acquire_transaction_success_marker()

Generates a token that will be written to the datastore (under "viur-transactionmarker") if the transaction

start_data_access_log()

Clears our internal access log (which keeps track of which entries have been accessed in the current

startDataAccessLog()

end_data_access_log([outer_access_log])

Retrieves the set of entries accessed so far.

endDataAccessLog([outerAccessLog])

Module Contents

core.db.utils.fix_unindexable_properties(entry, *, keep_exclusions=True)

Recursively walk the given Entity and add all properties to the list of unindexed properties if they contain a string longer than 1500 bytes (which is maximum size of a string that can be indexed). The datastore would return an error otherwise. https://cloud.google.com/datastore/docs/concepts/limits?hl=en#limits

Parameters:
  • entry (core.db.types.Entity) – The entity to fix (inplace)

  • keep_exclusions (bool) – If true, keep the properties already included in exclude_from_indexes. Otherwise, ignore them and exclude only non-indexable properties.

Returns:

The fixed entity

Return type:

core.db.types.Entity

core.db.utils.normalize_key(key)

Normalizes a datastore key (replacing _application with the current one)

Parameters:

key (Union[None, core.db.types.Key, str]) – Key to be normalized.

Returns:

Normalized key in string representation.

Return type:

Union[None, core.db.types.Key]

core.db.utils.normalizeKey(key)
Parameters:

key (Union[None, core.db.types.Key])

Return type:

Union[None, core.db.types.Key]

core.db.utils.key_helper(in_key, target_kind, additional_allowed_kinds=(), adjust_kind=False)
Parameters:
  • in_key (Union[core.db.types.Key, str, int])

  • target_kind (str)

  • additional_allowed_kinds (Union[List[str], Tuple[str]])

  • adjust_kind (bool)

Return type:

core.db.types.Key

core.db.utils.keyHelper(inKey, targetKind, additionalAllowedKinds=(), adjust_kind=False)
Parameters:
  • inKey (Union[core.db.types.Key, str, int])

  • targetKind (str)

  • additionalAllowedKinds (Union[List[str], Tuple[str]])

  • adjust_kind (bool)

Return type:

core.db.types.Key

core.db.utils.is_in_transaction()
Return type:

bool

core.db.utils.IsInTransaction()
Return type:

bool

core.db.utils.get_or_insert(key, **kwargs)

Either creates a new entity with the given key, or returns the existing one.

Its guaranteed that there is no race-condition here; it will never overwrite a previously created entity. Extra keyword arguments passed to this function will be used to populate the entity if it has to be created; otherwise they are ignored.

Parameters:

key (core.db.types.Key) – The key which will be fetched or created.

Returns:

Returns the fetched or newly created Entity.

Return type:

core.db.types.Entity

core.db.utils.GetOrInsert(key, **kwargs)
Parameters:
Return type:

core.db.types.Entity

core.db.utils.encodeKey(key)

Return the given key encoded as string (mimicking the old str() behaviour of keys)

Parameters:

key (core.db.types.Key)

Return type:

str

core.db.utils.acquire_transaction_success_marker()

Generates a token that will be written to the datastore (under “viur-transactionmarker”) if the transaction completes successfully. Currently only used by deferredTasks to check if the task should actually execute or if the transaction it was created in failed. :return: Name of the entry in viur-transactionmarker

Return type:

str

core.db.utils.start_data_access_log()

Clears our internal access log (which keeps track of which entries have been accessed in the current request). The old set of accessed entries is returned so that it can be restored with server.db.popAccessData() in case of nested caching. You must call popAccessData afterwards, otherwise we’ll continue to log all entries accessed in subsequent request on the same thread! :return: t.Set of old accessed entries

Return type:

Set[Union[core.db.types.Key, str]]

core.db.utils.startDataAccessLog()
Return type:

Set[Union[core.db.types.Key, str]]

core.db.utils.end_data_access_log(outer_access_log=None)

Retrieves the set of entries accessed so far.

To clean up and restart the log, call viur.datastore.startAccessDataLog().

If you called server.db.startAccessDataLog() before, you can re-apply the old log using the outerAccessLog param. Otherwise, it will disable the access log.

Parameters:
  • outerAccessLog – State of your log returned by server.db.startAccessDataLog()

  • outer_access_log (Optional[Set[Union[core.db.types.Key, str]]])

Returns:

t.Set of entries accessed

Return type:

Optional[Set[Union[core.db.types.Key, str]]]

core.db.utils.endDataAccessLog(outerAccessLog=None)
Parameters:

outerAccessLog (Optional[Set[Union[core.db.types.Key, str]]])

Return type:

Optional[Set[Union[core.db.types.Key, str]]]