1.9.30 sync.
[gae.git] / python / google / appengine / api / datastore_errors.py
bloba285af57db937a8074d64a18de83ab5b2c0537a7
1 #!/usr/bin/env python
3 # Copyright 2007 Google Inc.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
22 """Errors used in the Python datastore API."""
36 class Error(Exception):
37 """Base datastore error type.
38 """
40 class BadValueError(Error):
41 """Raised by Entity.__setitem__(), Query.__setitem__(), Get(), and others
42 when a property value or filter value is invalid.
43 """
45 class BadPropertyError(Error):
46 """Raised by Entity.__setitem__() when a property name isn't a string.
47 """
49 class BadRequestError(Error):
50 """Raised by datastore calls when the parameter(s) are invalid.
51 """
53 class EntityNotFoundError(Error):
54 """DEPRECATED: Raised by Get() when the requested entity is not found.
55 """
57 class BadArgumentError(Error):
58 """Raised by Query.Order(), Iterator.Next(), and others when they're
59 passed an invalid argument.
60 """
62 class QueryNotFoundError(Error):
63 """DEPRECATED: Raised by Iterator methods when the Iterator is invalid. This
64 should not happen during normal usage; it protects against malicious users
65 and system errors.
66 """
68 class TransactionNotFoundError(Error):
69 """DEPRECATED: Raised by RunInTransaction. This is an internal error; you
70 should not see this.
71 """
73 class Rollback(Error):
74 """May be raised by transaction functions when they want to roll back
75 instead of committing. Note that *any* exception raised by a transaction
76 function will cause a rollback. This is purely for convenience. See
77 datastore.RunInTransaction for details.
78 """
80 class TransactionFailedError(Error):
81 """Raised by RunInTransaction methods when the transaction could not be
82 committed, even after retrying. This is usually due to high contention.
83 """
85 class BadFilterError(Error):
86 """Raised by Query.__setitem__() and Query.Run() when a filter string is
87 invalid.
88 """
89 def __init__(self, filter):
90 self.filter = filter
91 message = (u'invalid filter: %s.' % self.filter).encode('utf-8')
92 super(BadFilterError, self).__init__(message)
94 class BadQueryError(Error):
95 """Raised by Query when a query or query string is invalid.
96 """
98 class BadKeyError(Error):
99 """Raised by Key.__str__ when the key is invalid.
102 class InternalError(Error):
103 """An internal datastore error. Please report this to Google.
106 class NeedIndexError(Error):
107 """No matching index was found for a query that requires an index. Check
108 the Indexes page in the Admin Console and your index.yaml file.
111 def __init__(self, error, original_message=None, header=None, yaml_index=None,
112 xml_index=None):
113 super(NeedIndexError, self).__init__(error)
114 self._original_message = original_message
115 self._header = header
116 self._yaml_index = yaml_index
117 self._xml_index = xml_index
119 def OriginalMessage(self):
120 return self._original_message
122 def Header(self):
123 return self._header
125 def YamlIndex(self):
126 return self._yaml_index
128 def XmlIndex(self):
129 return self._xml_index
131 class ReferencePropertyResolveError(Error):
132 """An error occurred while trying to resolve a ReferenceProperty."""
135 class Timeout(Error):
136 """The datastore operation timed out, or the data was temporarily
137 unavailable. This can happen when you attempt to put, get, or delete too
138 many entities or an entity with too many properties, or if the datastore is
139 overloaded or having trouble.
142 class CommittedButStillApplying(Timeout):
143 """The write or transaction was committed, but some entities or index rows
144 may not have been fully updated. Those updates should automatically be
145 applied soon. You can roll them forward immediately by reading one of the
146 entities inside a transaction.