From: Mike Bayer Date: Tue, 19 Dec 2006 20:52:32 +0000 (+0000) Subject: - fix to MapperExtension create_instance so that entity_name properly associated X-Git-Tag: rel_0_3_4~69 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dadf1c3792518146fcf0a96242b555b754579c50;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - fix to MapperExtension create_instance so that entity_name properly associated with new instance --- diff --git a/CHANGES b/CHANGES index 7b44e4c85c..dff9e71c93 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,6 @@ - added "BIGSERIAL" support for postgres table with PGBigInteger/autoincrement +- fix to MapperExtension create_instance so that entity_name properly associated +with new instance 0.3.3 - string-based FROM clauses fixed, i.e. select(..., from_obj=["sometext"]) diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index 78fd3a1cc2..46ef5f60fa 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -1187,6 +1187,8 @@ class Mapper(object): instance = self.extension.create_instance(self, context, row, self.class_) if instance is EXT_PASS: instance = self._create_instance(context.session) + else: + instance._entity_name = self.entity_name if self.__should_log_debug: self.__log_debug("_instance(): created new instance %s identity %s" % (mapperutil.instance_str(instance), str(identitykey))) context.identity_map[identitykey] = instance @@ -1398,7 +1400,8 @@ def has_identity(object): return hasattr(object, '_instance_key') def has_mapper(object): - """returns True if the given object has a mapper association""" + """return True if the given object has had a mapper association set up, either through loading, + or via insertion in a session.""" return hasattr(object, '_entity_name') diff --git a/test/orm/mapper.py b/test/orm/mapper.py index 533faed6de..4bcaf07cb4 100644 --- a/test/orm/mapper.py +++ b/test/orm/mapper.py @@ -760,7 +760,20 @@ class LazyTest(MapperSuperTest): self.assert_result([u], User, {'user_id' : 7, 'addresses' : (Address, [{'address_id' : 1}])}, ) - + + def testcreateinstance(self): + class Ext(MapperExtension): + def create_instance(self, *args, **kwargs): + return User() + m = mapper(Address, addresses) + m = mapper(User, users, extension=Ext(), properties = dict( + addresses = relation(Address, lazy=True), + )) + + q = create_session().query(m) + l = q.select(); + self.assert_result(l, User, *user_address_result) + def testorderby(self): m = mapper(Address, addresses)