]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- [bug] Fixed identity_key() function which
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 11 Jun 2012 14:11:14 +0000 (10:11 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 11 Jun 2012 14:11:14 +0000 (10:11 -0400)
was not accepting a scalar argument
for the identity.  [ticket:2508].

CHANGES
lib/sqlalchemy/orm/util.py
test/orm/test_utils.py

diff --git a/CHANGES b/CHANGES
index fcf71433c827aa5e34a9b83ad625dd02628702ec..dd21697f7efc88563c2d3eb8d3e412e45f60efa2 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -28,6 +28,10 @@ CHANGES
     flush() is no longer deprecated, as some
     valid use cases have been identified.  
 
+  - [bug] Fixed identity_key() function which 
+    was not accepting a scalar argument 
+    for the identity.  [ticket:2508].
+
 - engine
   - [bug] Fixed memory leak in C version of
     result proxy whereby DBAPIs which don't deliver
index 9d81913cb09b99c902960d491124ed60c539390c..9e9c909c3c37b673b1f335a5c0522bb31c5c7e56 100644 (file)
@@ -199,7 +199,7 @@ def identity_key(*args, **kwargs):
                 % ", ".join(kwargs.keys()))
         mapper = class_mapper(class_)
         if "ident" in locals():
-            return mapper.identity_key_from_primary_key(ident)
+            return mapper.identity_key_from_primary_key(util.to_list(ident))
         return mapper.identity_key_from_row(row)
     instance = kwargs.pop("instance")
     if kwargs:
index 62a8500bd4cce60f9ffab944f876834ef936f6c8..617f1d5384f9c38f2db1f17ebadd004f68c042d5 100644 (file)
@@ -198,6 +198,16 @@ class IdentityKeyTest(_fixtures.FixtureTest):
         key = util.identity_key(User, ident=[1])
         eq_(key, (User, (1,)))
 
+    def test_identity_key_scalar(self):
+        User, users = self.classes.User, self.tables.users
+
+        mapper(User, users)
+
+        key = util.identity_key(User, 1)
+        eq_(key, (User, (1,)))
+        key = util.identity_key(User, ident=1)
+        eq_(key, (User, (1,)))
+
     def test_identity_key_2(self):
         users, User = self.tables.users, self.classes.User