Skip to content

deprecate aliased=True, from_joinpoint=True, string join names / multijoin, joining to Core via ORM property #4705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zzzeek opened this issue May 31, 2019 · 10 comments
Labels
Milestone

Comments

@zzzeek
Copy link
Member

zzzeek commented May 31, 2019

in the interests of allowing select().join() to be a thing for Core and ORM at the same time, removing the major complexity of aliased=True should help. In #4704 we see that nobody has noticed aliased=True wasn't working that great, and a code search is turning up very few people actually using this API, although codesearch hits are vastly overwhelmed by projects that have bundled SQLAlchemy's source code and example suite. Within Openstack, there are three projects using it extremely minimally:

http://codesearch.openstack.org/?q=aliased%3DTrue&i=nope&files=&repos=

on github I can barely find one or two projects legitimately using it.

aliased=True was made back before aliased() existed, nor did of_type(). Using explicit aliases now is pretty easy:

   ba = aliased(Bar)
   q = q.join(Foo.bar.of_type(ba))

or

q = q.join(ba, Foo.bar)

@zzzeek zzzeek added the orm label May 31, 2019
@zzzeek zzzeek added this to the 1.4 milestone May 31, 2019
@zzzeek zzzeek changed the title deprecate aliased=True deprecate aliased=True and from_joinpoint=True May 31, 2019
@zzzeek
Copy link
Member Author

zzzeek commented May 31, 2019

one issue is that we can't get rid of mapper-level with_polymorphic as that's a very useful feature. Most of the complexity of aliased=True is also used for with_polymorphic.

@zzzeek
Copy link
Member Author

zzzeek commented May 31, 2019

it's still worth getting rid of it just doesn't take that much code out of query.py.

@zzzeek
Copy link
Member Author

zzzeek commented Jun 4, 2019

Update, it does, because aliased=True / from_joinpoint are the only reason we need to be applying adaptation per call to filter(), having(), order_by(), group_by(). Without them, all the adaption becomes at once when we create the SELECT, that is, we can move it all to one single adaption to ._whereclause , ._order_by etc. This means we can unify with base select() way more easily, we can use the same methods for base select() as we do for ORM select() and we greatly reduce call overhead. it's getting close to where we need to have 2.0 going at the same time.

@zzzeek zzzeek changed the title deprecate aliased=True and from_joinpoint=True deprecate aliased=True and from_joinpoint=True, allows moving clause adaption to the ORM compile phase Jun 4, 2019
@zzzeek
Copy link
Member Author

zzzeek commented Jun 26, 2019

Here is another form_joinpoiint use case that would have to go away:

            OrderAlias = aliased(Order)

            sess.query(User, OrderAlias, Item.description)
            .join(OrderAlias, "orders")
            .join("items", from_joinpoint=True)
            .filter_by(description="item 3")
            .order_by(User.id, OrderAlias.id)

so in that case, the assertion needs to encourage them to do:


            sess.query(User, OrderAlias, Item.description)
            .join(OrderAlias, "orders")
            .join(Order.items, )

which means we start to have to deprecate the whole concept of join() accepting string relationship names and then the whole idea of join("a", "b", "c", ..) should go as well, certainly in 2.0 that should be gone. that's a big change.

@zzzeek zzzeek changed the title deprecate aliased=True and from_joinpoint=True, allows moving clause adaption to the ORM compile phase deprecate aliased=True and from_joinpoint=True, string join names / multijoin, allows moving clause adaption to the ORM compile phase Jun 26, 2019
@zzzeek zzzeek changed the title deprecate aliased=True and from_joinpoint=True, string join names / multijoin, allows moving clause adaption to the ORM compile phase deprecate aliased=True, from_joinpoint=True, string join names / multijoin, joining to Core via ORM property Apr 7, 2020
@zzzeek
Copy link
Member Author

zzzeek commented Apr 7, 2020

this use case has to be depreacted as well so that more implicit aliasing can be removed:

            sess.query(Company)
            .join(people.join(engineers), Company.employees)
            .filter(Engineer.name == "dilbert"),

the correct pattern should be:

            pjoin = with_polymorphic(Person, [Engineer])
            sess.query(Company)
            .join(pjoin, Company.employees)
            .filter(Engineer.name == "dilbert"),

or join(Company.employees.of_type(pjoin))

@zzzeek
Copy link
Member Author

zzzeek commented Apr 7, 2020

I want to see if I can do these deprecations first, and get the tests set up, before I merge https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/1599 . this means I'll have to port to 1599 but I want this basic set of deps to be set up before we take a huge left turn with 1599.

@sqla-tester
Copy link
Collaborator

Mike Bayer referenced this issue:

Unify Query and select() , move all processing to compile phase https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/1599

sqlalchemy-bot pushed a commit that referenced this issue May 4, 2020

Verified

This commit was signed with the committer’s verified signature.
st0012 Stan Lo
For a 1.4 / 1.3 merge, rewrite the documentation for
Query.join() to indicate calling forms that are now considered
legacy, including the use of strings in join(), sending a
series of join paths in one call, and using the aliased=True
flag.   update the elementtree examples as well to use aliased()
(they are much simpler to understand this way too) and update
other links.

Also improve docs for aliased() and some other ORM targets
such as PropComparator.

Change-Id: I636e3a9130dc5509e51c2cf60a52f38fcadffbc6
References: #4705
(cherry picked from commit 9f6b67a)
sqlalchemy-bot pushed a commit that referenced this issue May 4, 2020
For a 1.4 / 1.3 merge, rewrite the documentation for
Query.join() to indicate calling forms that are now considered
legacy, including the use of strings in join(), sending a
series of join paths in one call, and using the aliased=True
flag.   update the elementtree examples as well to use aliased()
(they are much simpler to understand this way too) and update
other links.

Also improve docs for aliased() and some other ORM targets
such as PropComparator.

Change-Id: I636e3a9130dc5509e51c2cf60a52f38fcadffbc6
References: #4705
sqlalchemy-bot pushed a commit that referenced this issue May 25, 2020
Convert Query to do virtually all compile state computation
in the _compile_context() phase, and organize it all
such that a plain select() construct may also be used as the
source of information in order to generate ORM query state.
This makes it such that Query is not needed except for
its additional methods like from_self() which are all to
be deprecated.

The construction of ORM state will occur beyond the
caching boundary when the new execution model is integrated.

future select() gains a working join() and filter_by() method.
as we continue to rebase and merge each commit in the steps,
callcounts continue to bump around.  will have to look at
the final result when it's all in.

References: #5159
References: #4705
References: #4639
References: #4871
References: #5010

Change-Id: I19e05b3424b07114cce6c439b05198ac47f7ac10
@zzzeek
Copy link
Member Author

zzzeek commented Oct 12, 2020

we don't need to deprecate multi-join as Query is legacy overall in any case.

@sqla-tester
Copy link
Collaborator

Mike Bayer has proposed a fix for this issue in the master branch:

Deprecate strings indicating attribute names https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/2303

@zzzeek
Copy link
Member Author

zzzeek commented Oct 13, 2020

we don't need to deprecate multi-join as Query is legacy overall in any case.

ah we've already documented it https://docs.sqlalchemy.org/en/14/changelog/migration_20.html#orm-query-chaining-using-lists-of-attributes-rather-than-individual-calls-removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants