def test_no_orphan(self):

        users, Address, addresses, User = (
            self.tables.users,
            self.classes.Address,
            self.tables.addresses,
            self.classes.User)

        mapper(User, users, properties={
            'addresses': relationship(
                Address, cascade="all,delete-orphan", lazy='joined')
        })
        mapper(Address, addresses)

        sess = create_session()
        user = sess.query(User).get(7)
        assert getattr(User, 'addresses').\
            hasparent(
                sa.orm.attributes.instance_state(
                    user.addresses[0]), optimistic=True)
        assert not sa.orm.class_mapper(Address).\
            _is_orphan(
                sa.orm.attributes.instance_state(user.addresses[0]))
An eagerly loaded child object is not marked as an orphan
dataset/ETHPy150Open zzzeek/sqlalchemy/test/orm/test_eager_relations.py/EagerTest.test_no_orphan