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.
40 class BadValueError(Error
):
41 """Raised by Entity.__setitem__(), Query.__setitem__(), Get(), and others
42 when a property value or filter value is invalid.
45 class BadPropertyError(Error
):
46 """Raised by Entity.__setitem__() when a property name isn't a string.
49 class BadRequestError(Error
):
50 """Raised by datastore calls when the parameter(s) are invalid.
53 class EntityNotFoundError(Error
):
54 """DEPRECATED: Raised by Get() when the requested entity is not found.
57 class BadArgumentError(Error
):
58 """Raised by Query.Order(), Iterator.Next(), and others when they're
59 passed an invalid argument.
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
68 class TransactionNotFoundError(Error
):
69 """DEPRECATED: Raised by RunInTransaction. This is an internal error; you
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.
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.
85 class BadFilterError(Error
):
86 """Raised by Query.__setitem__() and Query.Run() when a filter string is
89 def __init__(self
, 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.
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,
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
126 return self
._yaml
_index
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.