summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/orm/session.py8
-rw-r--r--lib/sqlalchemy/orm/state.py11
-rw-r--r--lib/sqlalchemy/test/util.py11
-rw-r--r--lib/sqlalchemy/util.py2
4 files changed, 22 insertions, 10 deletions
diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py
index 391e78fdb..7641905f0 100644
--- a/lib/sqlalchemy/orm/session.py
+++ b/lib/sqlalchemy/orm/session.py
@@ -1337,7 +1337,8 @@ class Session(object):
if objects:
util.warn_deprecated(
"The 'objects' argument to session.flush() is deprecated; "
- "Please do not add objects to the session which should not yet be persisted.")
+ "Please do not add objects to the session which should not "
+ "yet be persisted.")
if self._flushing:
raise sa_exc.InvalidRequestError("Session is already flushing")
@@ -1400,7 +1401,10 @@ class Session(object):
["any parent '%s' instance "
"via that classes' '%s' attribute" %
(cls.__name__, key)
- for (key, cls) in chain(*(m.delete_orphans for m in _state_mapper(state).iterate_to_root()))])
+ for (key, cls) in chain(*(
+ m.delete_orphans for m in _state_mapper(state).iterate_to_root()
+ ))
+ ])
raise exc.FlushError(
"Instance %s is an unsaved, pending instance and is an "
"orphan (is not attached to %s)" % (
diff --git a/lib/sqlalchemy/orm/state.py b/lib/sqlalchemy/orm/state.py
index 25466b3c7..2b43d2cac 100644
--- a/lib/sqlalchemy/orm/state.py
+++ b/lib/sqlalchemy/orm/state.py
@@ -313,9 +313,7 @@ class InstanceState(object):
return self.obj()
def modified_event(self, dict_, attr, should_copy, previous, passive=PASSIVE_OFF):
- needs_committed = attr.key not in self.committed_state
-
- if needs_committed:
+ if attr.key not in self.committed_state:
if previous is NEVER_SET:
if passive:
if attr.key in dict_:
@@ -326,18 +324,17 @@ class InstanceState(object):
if should_copy and previous not in (None, NO_VALUE, NEVER_SET):
previous = attr.copy(previous)
- if needs_committed:
- self.committed_state[attr.key] = previous
+ self.committed_state[attr.key] = previous
if not self.modified:
instance_dict = self._instance_dict()
if instance_dict:
instance_dict._modified.add(self)
- self.modified = True
- if self._strong_obj is None:
self._strong_obj = self.obj()
+ self.modified = True
+
def commit(self, dict_, keys):
"""Commit attributes.
diff --git a/lib/sqlalchemy/test/util.py b/lib/sqlalchemy/test/util.py
index cd73b44d0..ff2c3d7b7 100644
--- a/lib/sqlalchemy/test/util.py
+++ b/lib/sqlalchemy/test/util.py
@@ -64,4 +64,15 @@ class RandomSet(set):
self.remove(item)
return item
+ def union(self, other):
+ return RandomSet(set.union(self, other))
+
+ def difference(self, other):
+ return RandomSet(set.difference(self, other))
+
+ def intersection(self, other):
+ return RandomSet(set.intersection(self, other))
+
+ def copy(self):
+ return RandomSet(self)
\ No newline at end of file
diff --git a/lib/sqlalchemy/util.py b/lib/sqlalchemy/util.py
index 97270004b..c2c85a4c9 100644
--- a/lib/sqlalchemy/util.py
+++ b/lib/sqlalchemy/util.py
@@ -139,9 +139,9 @@ except ImportError:
dict.__repr__(self))
class frozendict(dict):
+ @property
def _blocked_attribute(obj):
raise AttributeError, "A frozendict cannot be modified."
- _blocked_attribute = property(_blocked_attribute)
__delitem__ = __setitem__ = clear = _blocked_attribute
pop = popitem = setdefault = update = _blocked_attribute