Commits

Mike Bayer  committed 5d7a234 Merge

Merge branch 'master' into rel_1_0

  • Participants
  • Parent commits 7fda4a2, 961ede0

Comments (0)

Files changed (3)

File doc/build/changelog/changelog_09.rst

     :released:
 
     .. change::
+        :tags: bug, ext
+        :versions: 1.0.0
+        :pullreq: bitbucket:24
+        :tickets: 3093
+
+        Fixed bug where :meth:`.MutableDict.setdefault` didn't return the
+        existing or new value.  Pull request courtesy Thomas Hervé.
+
+    .. change::
         :tags: feature, mssql
         :pullreq: github:98
         :versions: 1.0.0

File lib/sqlalchemy/ext/mutable.py

 
 
     def setdefault(self, key, value):
-        dict.setdefault(self, key, value)
+        result = dict.setdefault(self, key, value)
         self.changed()
+        return result
 
     def __delitem__(self, key):
         """Detect dictionary del events and emit change events."""

File test/ext/test_mutable.py

         sess.add(f1)
         sess.commit()
 
-        f1.data.setdefault('c', 'd')
+        eq_(f1.data.setdefault('c', 'd'), 'd')
         sess.commit()
 
         eq_(f1.data, {'a': 'b', 'c': 'd'})
 
-        f1.data.setdefault('c', 'q')
+        eq_(f1.data.setdefault('c', 'q'), 'd')
         sess.commit()
 
         eq_(f1.data, {'a': 'b', 'c': 'd'})