def _prepare_right_side(self, r_info, right, onclause, create_aliases, prop, overlap):
    info = r_info
    (right_mapper, right_selectable, right_is_aliased) = (getattr(info, 'mapper', None), info.selectable, getattr(info, 'is_aliased_class', False))
    if right_mapper:
        self._join_entities += (info,)
    if (right_mapper and prop and (not right_mapper.common_parent(prop.mapper))):
        raise sa_exc.InvalidRequestError(('Join target %s does not correspond to the right side of join condition %s' % (right, onclause)))
    if ((not right_mapper) and prop):
        right_mapper = prop.mapper
    need_adapter = False
    if (right_mapper and (right is right_selectable)):
        if (not right_selectable.is_derived_from(right_mapper.mapped_table)):
            raise sa_exc.InvalidRequestError(("Selectable '%s' is not derived from '%s'" % (right_selectable.description, right_mapper.mapped_table.description)))
        if isinstance(right_selectable, expression.SelectBase):
            right_selectable = right_selectable.alias()
            need_adapter = True
        right = aliased(right_mapper, right_selectable)
    aliased_entity = (right_mapper and (not right_is_aliased) and ((right_mapper.with_polymorphic and isinstance(right_mapper._with_polymorphic_selectable, expression.Alias)) or overlap))
    if ((not need_adapter) and (create_aliases or aliased_entity)):
        right = aliased(right, flat=True)
        need_adapter = True
    if need_adapter:
        self._filter_aliases = ORMAdapter(right, equivalents=((right_mapper and right_mapper._equivalent_columns) or {}), chain_to=self._filter_aliases)
    if isinstance(onclause, expression.ClauseElement):
        onclause = self._adapt_clause(onclause, True, True)
    if (aliased_entity and (not create_aliases)):
        self._mapper_loads_polymorphically_with(right_mapper, ORMAdapter(right, equivalents=right_mapper._equivalent_columns))
    return (right, onclause)
def _prepare_right_side(self, r_info, right, onclause, create_aliases, prop, overlap):
    info = r_info
    (right_mapper, right_selectable, right_is_aliased) = (getattr(info, 'mapper', None), info.selectable, getattr(info, 'is_aliased_class', False))
    if right_mapper:
        self._join_entities += (info,)
    if (right_mapper and prop and (not right_mapper.common_parent(prop.mapper))):
        raise sa_exc.InvalidRequestError(('Join target %s does not correspond to the right side of join condition %s' % (right, onclause)))
    if ((not right_mapper) and prop):
        right_mapper = prop.mapper
    need_adapter = False
    if (right_mapper and (right is right_selectable)):
        if (not right_selectable.is_derived_from(right_mapper.mapped_table)):
            raise sa_exc.InvalidRequestError(("Selectable '%s' is not derived from '%s'" % (right_selectable.description, right_mapper.mapped_table.description)))
        if isinstance(right_selectable, expression.SelectBase):
            right_selectable = right_selectable.alias()
            need_adapter = True
        right = aliased(right_mapper, right_selectable)
    aliased_entity = (right_mapper and (not right_is_aliased) and ((right_mapper.with_polymorphic and isinstance(right_mapper._with_polymorphic_selectable, expression.Alias)) or overlap))
    if ((not need_adapter) and (create_aliases or aliased_entity)):
        right = aliased(right, flat=True)
        need_adapter = True
    if need_adapter:
        self._filter_aliases = ORMAdapter(right, equivalents=((right_mapper and right_mapper._equivalent_columns) or {}), chain_to=self._filter_aliases)
    if isinstance(onclause, expression.ClauseElement):
        onclause = self._adapt_clause(onclause, True, True)
    if (aliased_entity and (not create_aliases)):
        self._mapper_loads_polymorphically_with(right_mapper, ORMAdapter(right, equivalents=right_mapper._equivalent_columns))
    return (right, onclause)