From: Mike Bayer Date: Sat, 17 Apr 2010 10:44:44 +0000 (-0400) Subject: a little bit of refinement X-Git-Tag: rel_0_6_0~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3cefadd926fdb470bf0672ed10b76685b8d32638;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git a little bit of refinement --- diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py index 391e78fdbd..7641905f03 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 25466b3c7d..2b43d2cacd 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 cd73b44d07..ff2c3d7b79 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 97270004b5..c2c85a4c93 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 diff --git a/test/perf/large_flush.py b/test/perf/large_flush.py index 5dd6f610fd..431a289449 100644 --- a/test/perf/large_flush.py +++ b/test/perf/large_flush.py @@ -70,7 +70,7 @@ mapper(A, a_table, inherits=Object, polymorphic_identity='A', SA_Metadata.create_all(engine) -@profiling.profiled('large_flush', always=True, sort=['cumulative']) +@profiling.profiled('large_flush', always=True, sort=['file']) def generate_error(): q = Q() for j in range(100): #at 306 the error does not pop out (depending on recursion depth)