summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2011-02-10 11:30:23 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2011-02-10 11:30:23 -0500
commite155b7b8640c18e5ca33d5529fbc11f4776ae4c5 (patch)
treeaf2d28a408de06917a75cf8142eec754d10c980f /lib/sqlalchemy
parent311fa4f8766c7cdecc7ec08aba57692611060c95 (diff)
downloadsqlalchemy-e155b7b8640c18e5ca33d5529fbc11f4776ae4c5.tar.gz
- An exception is raised in the unusual case that an
append or similar event on a collection occurs after the parent object has been dereferenced, which prevents the parent from being marked as "dirty" in the session. Will commit as a warning in 0.6. [ticket:2046]
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/orm/exc.py3
-rw-r--r--lib/sqlalchemy/orm/state.py9
2 files changed, 10 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/exc.py b/lib/sqlalchemy/orm/exc.py
index b86e5c7c3..3bfb2708c 100644
--- a/lib/sqlalchemy/orm/exc.py
+++ b/lib/sqlalchemy/orm/exc.py
@@ -40,6 +40,9 @@ class FlushError(sa.exc.SQLAlchemyError):
class UnmappedError(sa.exc.InvalidRequestError):
"""Base for exceptions that involve expected mappings not present."""
+class ObjectDereferencedError(sa.exc.SQLAlchemyError):
+ """An operation cannot complete due to an object being garbage collected."""
+
class DetachedInstanceError(sa.exc.SQLAlchemyError):
"""An attempt to access unloaded attributes on a
mapped instance that is detached."""
diff --git a/lib/sqlalchemy/orm/state.py b/lib/sqlalchemy/orm/state.py
index 7a93b5cb0..6b410a868 100644
--- a/lib/sqlalchemy/orm/state.py
+++ b/lib/sqlalchemy/orm/state.py
@@ -15,7 +15,8 @@ from sqlalchemy.util import EMPTY_SET
import weakref
from sqlalchemy import util
-from sqlalchemy.orm import exc as orm_exc, attributes, interfaces
+from sqlalchemy.orm import exc as orm_exc, attributes, interfaces,\
+ util as orm_util
from sqlalchemy.orm.attributes import PASSIVE_OFF, PASSIVE_NO_RESULT, \
PASSIVE_NO_FETCH, NEVER_SET, ATTR_WAS_SET, NO_VALUE
@@ -351,7 +352,11 @@ class InstanceState(object):
instance_dict._modified.add(self)
self._strong_obj = self.obj()
-
+ if self._strong_obj is None:
+ raise orm_exc.ObjectDereferencedError(
+ "Can't emit change event for attribute '%s' - parent object "
+ "of type %s has been garbage collected."
+ % (self.manager[attr.key], orm_util.state_class_str(self)))
self.modified = True
def commit(self, dict_, keys):