summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/unitofwork.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-04-05 16:13:51 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2010-04-05 16:13:51 -0400
commit49489ff21a6e4813567c80b87cf5a7f15119d29a (patch)
treeba43031f9a5e221b74a6794fb0cbef48122adf10 /lib/sqlalchemy/orm/unitofwork.py
parent233756a018dd54aa611ec8147bfda09a3c16268e (diff)
downloadsqlalchemy-49489ff21a6e4813567c80b87cf5a7f15119d29a.tar.gz
better assertions, the concern is that an object will change state and not have been
appropriately preprocessed
Diffstat (limited to 'lib/sqlalchemy/orm/unitofwork.py')
-rw-r--r--lib/sqlalchemy/orm/unitofwork.py27
1 files changed, 13 insertions, 14 deletions
diff --git a/lib/sqlalchemy/orm/unitofwork.py b/lib/sqlalchemy/orm/unitofwork.py
index 0c3f59562..702e77686 100644
--- a/lib/sqlalchemy/orm/unitofwork.py
+++ b/lib/sqlalchemy/orm/unitofwork.py
@@ -145,19 +145,17 @@ class UOWTransaction(object):
self.mappers[mapper].add(state)
self.states[state] = (isdelete, listonly)
- elif isdelete or listonly:
+ else:
existing_isdelete, existing_listonly = self.states[state]
- if not listonly and existing_listonly:
- raise Exception("Can't upgrade from listonly to save")
- if existing_isdelete != isdelete:
- raise Exception("Can't change delete flag")
+ if isdelete and not existing_delete:
+ raise Exception("Can't upgrade from a save to a delete")
def states_for_mapper(self, mapper, isdelete, listonly):
checktup = (isdelete, listonly)
for state in self.mappers[mapper]:
if self.states[state] == checktup:
yield state
-
+
def states_for_mapper_hierarchy(self, mapper, isdelete, listonly):
checktup = (isdelete, listonly)
for mapper in mapper.base_mapper.polymorphic_iterator():
@@ -235,7 +233,9 @@ class UOWTransaction(object):
for state, (isdelete, listonly) in self.states.iteritems():
if isdelete:
self.session._remove_newly_deleted(state)
- else: #if not listonly:
+ else:
+ # if listonly:
+ # debug... would like to see how many do this
self.session._register_newly_persistent(state)
log.class_logger(UOWTransaction)
@@ -272,8 +272,6 @@ class PropertyRecMixin(object):
self.delete = delete
self.fromparent = fromparent
- self.processed = set()
-
prop = dependency_processor.prop
if fromparent:
self._mappers = set(
@@ -291,29 +289,30 @@ class PropertyRecMixin(object):
self.dependency_processor,
self.delete
)
-
+
+ processed = ()
def _elements(self, uow):
for mapper in self._mappers:
for state in uow.mappers[mapper]:
if state in self.processed:
continue
(isdelete, listonly) = uow.states[state]
- if isdelete == self.delete:
+ if isdelete == self.delete and not listonly:
yield state
class GetDependentObjects(PropertyRecMixin, PreSortRec):
def __init__(self, *args):
- self.processed = set()
super(GetDependentObjects, self).__init__(*args)
-
+ self.processed = set()
+
def execute(self, uow):
states = list(self._elements(uow))
if states:
- self.processed.update(states)
if self.delete:
self.dependency_processor.presort_deletes(uow, states)
else:
self.dependency_processor.presort_saves(uow, states)
+ self.processed.update(states)
return True
else:
return False