summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/exc.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-06-23 14:45:47 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2012-06-23 14:45:47 -0400
commit0efac1d93e27220f2aa1ec09b282fb08a7bb02be (patch)
treedbd806874a223253d0c8f52465a77f7e0754c7a8 /lib/sqlalchemy/orm/exc.py
parentdf62f4501ee1ec37113477eb6a97068cc07faf5d (diff)
downloadsqlalchemy-0efac1d93e27220f2aa1ec09b282fb08a7bb02be.tar.gz
- move all of orm to use absolute imports
- break out key mechanics of loading objects into new "orm.loading" module, removing implementation details from both mapper.py and query.py. is analogous to persistence.py - some other cleanup and old cruft removal
Diffstat (limited to 'lib/sqlalchemy/orm/exc.py')
-rw-r--r--lib/sqlalchemy/orm/exc.py35
1 files changed, 15 insertions, 20 deletions
diff --git a/lib/sqlalchemy/orm/exc.py b/lib/sqlalchemy/orm/exc.py
index 9b3a78c43..d42dd42a7 100644
--- a/lib/sqlalchemy/orm/exc.py
+++ b/lib/sqlalchemy/orm/exc.py
@@ -5,14 +5,14 @@
# the MIT License: http://www.opensource.org/licenses/mit-license.php
"""SQLAlchemy ORM exceptions."""
-
-import sqlalchemy as sa
-orm_util = sa.util.importlater('sqlalchemy.orm', 'util')
+from .. import exc as sa_exc, util
+orm_util = util.importlater('sqlalchemy.orm', 'util')
+attributes = util.importlater('sqlalchemy.orm', 'attributes')
NO_STATE = (AttributeError, KeyError)
"""Exception types that may be raised by instrumentation implementations."""
-class StaleDataError(sa.exc.SQLAlchemyError):
+class StaleDataError(sa_exc.SQLAlchemyError):
"""An operation encountered database state that is unaccounted for.
Conditions which cause this to happen include:
@@ -41,17 +41,17 @@ class StaleDataError(sa.exc.SQLAlchemyError):
ConcurrentModificationError = StaleDataError
-class FlushError(sa.exc.SQLAlchemyError):
+class FlushError(sa_exc.SQLAlchemyError):
"""A invalid condition was detected during flush()."""
-class UnmappedError(sa.exc.InvalidRequestError):
+class UnmappedError(sa_exc.InvalidRequestError):
"""Base for exceptions that involve expected mappings not present."""
-class ObjectDereferencedError(sa.exc.SQLAlchemyError):
+class ObjectDereferencedError(sa_exc.SQLAlchemyError):
"""An operation cannot complete due to an object being garbage collected."""
-class DetachedInstanceError(sa.exc.SQLAlchemyError):
+class DetachedInstanceError(sa_exc.SQLAlchemyError):
"""An attempt to access unloaded attributes on a
mapped instance that is detached."""
@@ -61,7 +61,7 @@ class UnmappedInstanceError(UnmappedError):
def __init__(self, obj, msg=None):
if not msg:
try:
- mapper = sa.orm.class_mapper(type(obj))
+ mapper = orm_util.class_mapper(type(obj))
name = _safe_cls_name(type(obj))
msg = ("Class %r is mapped, but this instance lacks "
"instrumentation. This occurs when the instance is created "
@@ -88,7 +88,7 @@ class UnmappedClassError(UnmappedError):
def __reduce__(self):
return self.__class__, (None, self.args[0])
-class ObjectDeletedError(sa.exc.InvalidRequestError):
+class ObjectDeletedError(sa_exc.InvalidRequestError):
"""A refresh operation failed to retrieve the database
row corresponding to an object's known primary key identity.
@@ -112,28 +112,23 @@ class ObjectDeletedError(sa.exc.InvalidRequestError):
msg = "Instance '%s' has been deleted, or its "\
"row is otherwise not present." % orm_util.state_str(state)
- sa.exc.InvalidRequestError.__init__(self, msg)
+ sa_exc.InvalidRequestError.__init__(self, msg)
def __reduce__(self):
return self.__class__, (None, self.args[0])
-class UnmappedColumnError(sa.exc.InvalidRequestError):
+class UnmappedColumnError(sa_exc.InvalidRequestError):
"""Mapping operation was requested on an unknown column."""
-class NoResultFound(sa.exc.InvalidRequestError):
+class NoResultFound(sa_exc.InvalidRequestError):
"""A database result was required but none was found."""
-class MultipleResultsFound(sa.exc.InvalidRequestError):
+class MultipleResultsFound(sa_exc.InvalidRequestError):
"""A single database result was required but more than one were found."""
-# Legacy compat until 0.6.
-sa.exc.ConcurrentModificationError = ConcurrentModificationError
-sa.exc.FlushError = FlushError
-sa.exc.UnmappedColumnError
-
def _safe_cls_name(cls):
try:
cls_name = '.'.join((cls.__module__, cls.__name__))
@@ -145,7 +140,7 @@ def _safe_cls_name(cls):
def _default_unmapped(cls):
try:
- mappers = sa.orm.attributes.manager_of_class(cls).mappers
+ mappers = attributes.manager_of_class(cls).mappers
except NO_STATE:
mappers = {}
except TypeError: