def test_polymorphic_deferred(self): email_users, users = (self.tables.email_users, self.tables.users) mapper( User, users, polymorphic_identity="user", polymorphic_on=users.c.type, ) mapper( EmailUser, email_users, inherits=User, polymorphic_identity="emailuser", ) eu = EmailUser(name="user1", email_address="*****@*****.**") with fixture_session() as sess: sess.add(eu) sess.commit() with fixture_session() as sess: eu = sess.query(User).first() eu2 = pickle.loads(pickle.dumps(eu)) sess2 = fixture_session() sess2.add(eu2) assert "email_address" not in eu2.__dict__ eq_(eu2.email_address, "*****@*****.**")
def test_polymorphic_deferred(self): email_users, users = ( self.tables.email_users, self.tables.users, ) mapper(User, users, polymorphic_identity='user', polymorphic_on=users.c.type) mapper(EmailUser, email_users, inherits=User, polymorphic_identity='emailuser') eu = EmailUser(name="user1", email_address='*****@*****.**') sess = create_session() sess.add(eu) sess.flush() sess.expunge_all() eu = sess.query(User).first() eu2 = pickle.loads(pickle.dumps(eu)) sess2 = create_session() sess2.add(eu2) assert 'email_address' not in eu2.__dict__ eq_(eu2.email_address, '*****@*****.**')