[sqlalchemy-20] Remove ORM "from_self"

Bug #2004263 reported by Rodolfo Alonso
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
neutron
Fix Released
High
Rodolfo Alonso

Bug Description

The "from_self()" method in SQLAlchemy is deprecated in version 2.0.

The from_self() method takes an ORM query object, turns it into a subquery, then returns a new query object that will SELECT from that subquery, while transparently altering subsequent criteria added to the query to be stated in terms of the subquery. The current design direction of SQLAlchemy hopes to de-emphasize the "transparently altering criteria" part of the above use case, and to move users towards a more explicit and model of usage where a subquery should be created and used explicitly using the aliased() construct, which is now very mature and can be used in ways that were not available when from_self() was first introduced.

Reference: https://github.com/sqlalchemy/sqlalchemy/issues/5368

Changed in neutron:
assignee: nobody → Rodolfo Alonso (rodolfo-alonso-hernandez)
Changed in neutron:
status: New → In Progress
Revision history for this message
Mamatisa Nurmatov (isabek) wrote :
Changed in neutron:
importance: Undecided → High
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to neutron (master)

Reviewed: https://review.opendev.org/c/openstack/neutron/+/744512
Committed: https://opendev.org/openstack/neutron/commit/e98a268de4316c4f889925a3da6266e1c70306aa
Submitter: "Zuul (22348)"
Branch: master

commit e98a268de4316c4f889925a3da6266e1c70306aa
Author: Mike Bayer <email address hidden>
Date: Mon Aug 3 11:08:19 2020 -0400

    Propose replacement of ORM from_self()

    The from_self() method in SQLAlchemy is currently
    being considered for removal from the library,
    with a deprecation phase throughout 1.4 and then
    removal by SQLAlchemy 2.0.

    The from_self() method takes an ORM query object,
    turns it into a subquery, then returns a new query
    object that will SELECT from that subquery, while transparently
    altering subsequent criteria added to the query to
    be stated in terms of the subquery. The current
    design direction of SQLAlchemy hopes to
    de-emphasize the "transparently altering criteria"
    part of the above use case, and to move users towards a
    more explicit and model of usage where a subquery should
    be created and used explicitly using the aliased()
    construct, which is now very mature and can be used in ways
    that were not available when from_self() was first introduced.

    On the SQLAlchemy side, from_self() has proven to be one
    of the most difficult features to maintain and test
    as it can easily lead to extremely complicated scenarios, and
    while I am also experimenting with some alternatives that
    may still retain some of the "automatic translation" features,
    those features are still proving to add similar internal
    complexity which is having me lean towards the original
    plan of removing open-ended "entity translation" features
    like that of from_self() at least through the start
    of the 2.0 series.

    A code search for all of Openstack shows that the
    two files modified here are the only usages of the
    from_self() method throughout all of searchable Openstack
    code. This speaks to the general obscurity of this method,
    although neutron's Subnet code is actually using this
    method as intended. The new approach necessarily changes
    some of the method signatures here so that the explicit
    "subquery" entity can be passed; code searches again
    show that these methods are not being called anywhere
    outside, so the query_filter_service_subnets method
    becomes the private _query_entity_service_subnets method.

    References: https://github.com/sqlalchemy/sqlalchemy/issues/5368

    Closes-Bug: #2004263

    Change-Id: Icec998873221ac8e6a1566a157b2044c1f6cd7f3

Changed in neutron:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/neutron 22.0.0.0rc1

This issue was fixed in the openstack/neutron 22.0.0.0rc1 release candidate.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.