Use coercion rules for aliased() against select/union constructs
Calling :func:`_orm.aliased` against a :func:`_sql.select` or
:func:`_sql.union` / :class:`_sql.CompoundSelect` construct, which
previously failed with an obscure ``AttributeError`` regarding a missing
``.mapper`` attribute, now raises when using SQLAlchemy 2.1, and emits a
deprecation warning under SQLAlchemy 2.0 as it coerces the construct into a
subquery instead. This matches the behavior of other similar implicit
SELECT-to-FROM coercions. Pull request courtesy Rens Groothuijsen.
Fixes: #6274
Closes: #12433
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12433
Pull-request-sha:
416dde8509ac05b209400603d9e00bc82aa47c79
Change-Id: I63bdec71074b81fb85bf29e6ca0dd81cbe3f8cb3
(cherry picked from commit
16177b8c73e492e5adaad8f51095f9981831da41)