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."""
35 class Error(Exception):
36 """Base datastore error type.
39 class BadValueError(Error
):
40 """Raised by Entity.__setitem__(), Query.__setitem__(), Get(), and others
41 when a property value or filter value is invalid.
44 class BadPropertyError(Error
):
45 """Raised by Entity.__setitem__() when a property name isn't a string.
48 class BadRequestError(Error
):
49 """Raised by datastore calls when the parameter(s) are invalid.
52 class EntityNotFoundError(Error
):
53 """DEPRECATED: Raised by Get() when the requested entity is not found.
56 class BadArgumentError(Error
):
57 """Raised by Query.Order(), Iterator.Next(), and others when they're
58 passed an invalid argument.
61 class QueryNotFoundError(Error
):
62 """DEPRECATED: Raised by Iterator methods when the Iterator is invalid. This
63 should not happen during normal usage; it protects against malicious users
67 class TransactionNotFoundError(Error
):
68 """DEPRECATED: Raised by RunInTransaction. This is an internal error; you
72 class Rollback(Error
):
73 """May be raised by transaction functions when they want to roll back
74 instead of committing. Note that *any* exception raised by a transaction
75 function will cause a rollback. This is purely for convenience. See
76 datastore.RunInTransaction for details.
79 class TransactionFailedError(Error
):
80 """Raised by RunInTransaction methods when the transaction could not be
81 committed, even after retrying. This is usually due to high contention.
84 class BadFilterError(Error
):
85 """Raised by Query.__setitem__() and Query.Run() when a filter string is
88 def __init__(self
, filter):
90 message
= (u
'invalid filter: %s.' % self
.filter).encode('utf-8')
91 super(BadFilterError
, self
).__init
__(message
)
93 class BadQueryError(Error
):
94 """Raised by Query when a query or query string is invalid.
97 class BadKeyError(Error
):
98 """Raised by Key.__str__ when the key is invalid.
101 class InternalError(Error
):
102 """An internal datastore error. Please report this to Google.
105 class NeedIndexError(Error
):
106 """No matching index was found for a query that requires an index. Check
107 the Indexes page in the Admin Console and your index.yaml file.
110 def __init__(self
, error
, original_message
=None, header
=None, yaml_index
=None,
112 super(NeedIndexError
, self
).__init
__(error
)
113 self
._original
_message
= original_message
114 self
._header
= header
115 self
._yaml
_index
= yaml_index
116 self
._xml
_index
= xml_index
118 def OriginalMessage(self
):
119 return self
._original
_message
125 return self
._yaml
_index
128 return self
._xml
_index
130 class ReferencePropertyResolveError(Error
):
131 """An error occurred while trying to resolve a ReferenceProperty."""
134 class Timeout(Error
):
135 """The datastore operation timed out, or the data was temporarily
136 unavailable. This can happen when you attempt to put, get, or delete too
137 many entities or an entity with too many properties, or if the datastore is
138 overloaded or having trouble.
141 class CommittedButStillApplying(Timeout
):
142 """The write or transaction was committed, but some entities or index rows
143 may not have been fully updated. Those updates should automatically be
144 applied soon. You can roll them forward immediately by reading one of the
145 entities inside a transaction.