From 5b8e5d381c710b0d813022467acc56265e98a27d Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 11 Jun 2012 10:08:33 -0400 Subject: [PATCH] - [bug] Fixed identity_key() function which was not accepting a scalar argument for the identity. [ticket:2508]. Also in 0.7.8. --- CHANGES | 5 +++++ lib/sqlalchemy/orm/util.py | 2 +- test/orm/test_utils.py | 10 ++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index a57f0aa87a..c29ea98a45 100644 --- a/CHANGES +++ b/CHANGES @@ -136,6 +136,11 @@ CHANGES valid use cases have been identified. Also in 0.7.8. + - [bug] Fixed identity_key() function which + was not accepting a scalar argument + for the identity. [ticket:2508]. Also + in 0.7.8. + - [feature] Query now "auto correlates" by default in the same way as select() does. Previously, a Query used as a subquery diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py index 8403ce6738..51aaa31524 100644 --- a/lib/sqlalchemy/orm/util.py +++ b/lib/sqlalchemy/orm/util.py @@ -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: diff --git a/test/orm/test_utils.py b/test/orm/test_utils.py index 62a8500bd4..617f1d5384 100644 --- a/test/orm/test_utils.py +++ b/test/orm/test_utils.py @@ -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 -- 2.47.3