]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
a little bit of refinement
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 17 Apr 2010 10:44:44 +0000 (06:44 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 17 Apr 2010 10:44:44 +0000 (06:44 -0400)
lib/sqlalchemy/orm/session.py
lib/sqlalchemy/orm/state.py
lib/sqlalchemy/test/util.py
lib/sqlalchemy/util.py
test/perf/large_flush.py

index 391e78fdbdec1ba61b36249addec18af881ab555..7641905f03608cca5f52dc278468755f398b7d80 100644 (file)
@@ -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)" % (
index 25466b3c7d6de2dda95d40fffc90abb4995d6fc5..2b43d2cacd9128070f3e656004ec57eed159726c 100644 (file)
@@ -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.
 
index cd73b44d07917cd1013a03f0b6c144fb95c966c1..ff2c3d7b79bbc373a79e7b3b6729e0a1dec59f03 100644 (file)
@@ -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
index 97270004b5295bf689ce7aef6de5949093988e98..c2c85a4c93c26f4993a1a29b76c1721a18a332d2 100644 (file)
@@ -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
index 5dd6f610fd4eb1f54cf89cd798edfd9cb0f82c81..431a289449456433f7b4c75264a97c3209f9aa32 100644 (file)
@@ -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)