Notice: Over the next few months, we're reorganizing the App Engine documentation site to make it easier to find content and better align with the rest of Google Cloud products. The same content will be available, but the navigation will now match the rest of the Cloud products. If you have feedback or questions as you navigate the site, click Send Feedback.

Python 2 is no longer supported by the community. We recommend that you migrate Python 2 apps to Python 3.
Stay organized with collections Save and categorize content based on your preferences.

Source code for google.appengine.api.datastore_errors

#!/usr/bin/env python
# Copyright 2007 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# See the License for the specific language governing permissions and
# limitations under the License.

"""Errors used in the Python datastore API."""

[docs]class Error(Exception): """Base datastore error type. """
[docs]class BadValueError(Error): """Raised by Entity.__setitem__(), Query.__setitem__(), Get(), and others when a property value or filter value is invalid. """
[docs]class BadPropertyError(Error): """Raised by Entity.__setitem__() when a property name isn't a string. """
[docs]class BadRequestError(Error): """Raised by datastore calls when the parameter(s) are invalid. """
[docs]class EntityNotFoundError(Error): """DEPRECATED: Raised by Get() when the requested entity is not found. """
[docs]class BadArgumentError(Error): """Raised by Query.Order(), Iterator.Next(), and others when they're passed an invalid argument. """
[docs]class QueryNotFoundError(Error): """DEPRECATED: Raised by Iterator methods when the Iterator is invalid. This should not happen during normal usage; it protects against malicious users and system errors. """
[docs]class TransactionNotFoundError(Error): """DEPRECATED: Raised by RunInTransaction. This is an internal error; you should not see this. """
[docs]class Rollback(Error): """May be raised by transaction functions when they want to roll back instead of committing. Note that *any* exception raised by a transaction function will cause a rollback. This is purely for convenience. See datastore.RunInTransaction for details. """
[docs]class TransactionFailedError(Error): """Raised by RunInTransaction methods when the transaction could not be committed, even after retrying. This is usually due to high contention. """
[docs]class BadFilterError(Error): """Raised by Query.__setitem__() and Query.Run() when a filter string is invalid. """ def __init__(self, filter): self.filter = filter message = (u'invalid filter: %s.' % self.filter).encode('utf-8') super(BadFilterError, self).__init__(message)
[docs]class BadQueryError(Error): """Raised by Query when a query or query string is invalid. """
[docs]class BadKeyError(Error): """Raised by Key.__str__ when the key is invalid. """
[docs]class InternalError(Error): """An internal datastore error. Please report this to Google. """
[docs]class NeedIndexError(Error): """No matching index was found for a query that requires an index. Check the Indexes page in the Admin Console and your index.yaml file. """ def __init__(self, error, original_message=None, header=None, yaml_index=None, xml_index=None): super(NeedIndexError, self).__init__(error) self._original_message = original_message self._header = header self._yaml_index = yaml_index self._xml_index = xml_index
[docs] def OriginalMessage(self): return self._original_message
[docs] def Header(self): return self._header
[docs] def YamlIndex(self): return self._yaml_index
[docs] def XmlIndex(self): return self._xml_index
[docs]class ReferencePropertyResolveError(Error): """An error occurred while trying to resolve a ReferenceProperty."""
[docs]class Timeout(Error): """The datastore operation timed out, or the data was temporarily unavailable. This can happen when you attempt to put, get, or delete too many entities or an entity with too many properties, or if the datastore is overloaded or having trouble. """
[docs]class CommittedButStillApplying(Timeout): """The write or transaction was committed, but some entities or index rows may not have been fully updated. Those updates should automatically be applied soon. You can roll them forward immediately by reading one of the entities inside a transaction. """