diff options
author | Elrond <elrond+mediagoblin.org@samba-tng.org> | 2012-11-28 13:50:31 +0100 |
---|---|---|
committer | Sebastian Spaeth <Sebastian@SSpaeth.de> | 2012-11-28 13:52:41 +0100 |
commit | 329e39034b2ef2a9663fc2de16c8eae6c0313fdc (patch) | |
tree | b50301d0443999129b8b9f0424e748b5185797e0 | |
parent | fa2f6ba1627b6ae50ada1892986b35ec8323d703 (diff) | |
download | mediagoblin-329e39034b2ef2a9663fc2de16c8eae6c0313fdc.tar.lz mediagoblin-329e39034b2ef2a9663fc2de16c8eae6c0313fdc.tar.xz mediagoblin-329e39034b2ef2a9663fc2de16c8eae6c0313fdc.zip |
Add "commit" argument to Base model delete()
In case we want to bundle db actions into a single transaction, we
can now use delete(commit=False) to prevent the transaction from being
committed immediately. This is useful when e.g. deleting a User() and
thousands of his MediaEntries in a single commit.
Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
-rw-r--r-- | mediagoblin/db/sql/base.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/mediagoblin/db/sql/base.py b/mediagoblin/db/sql/base.py index 838080b0..e10e7739 100644 --- a/mediagoblin/db/sql/base.py +++ b/mediagoblin/db/sql/base.py @@ -79,11 +79,13 @@ class GMGTableBase(object): sess.add(self) sess.commit() - def delete(self): + def delete(self, commit=True): + """Delete the object and commit the change immediately by default""" sess = object_session(self) assert sess is not None, "Not going to delete detached %r" % self sess.delete(self) - sess.commit() + if commit: + sess.commit() Base = declarative_base(cls=GMGTableBase) |