Skip to content

Improve re-writer implementation, fixing chain and adding support to callables #1337

Description

@CaselIT

ive just read the source code for chain() and it's a bit of a disaster. because if i do this:

w = writer1.chain(writer2).chain(writer3)

writer2 is lost. it's doing the chaining wrong. my high school comp sci teacher would be unimpressed

it works for your use case right now because it only handles exactly two writers. but if we fix it to correctly implement chaining then it would not work for your case in the general sense.

we can fix both issues at once by 1. fixing the chaining so that if self._chain is non-None we traverse the list through to the end for the linked list append, and 2. looking at the type of object sent and if it's just a callable, wrapping it in a helper object CallableRewriter that uses that callable and also supports the rest of the Rewriter protocol including self._chain.

Originally posted by @zzzeek in #1332 (reply in thread)

Activity

  1. added a commit that references this issue on Nov 29, 2023
    d43b320
  2. sqla-tester commented on Nov 30, 2023

    @sqla-tester
    Collaborator

    l-hedgehog has proposed a fix for this issue in the main branch:

    Improve Rewriter implementation https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/4990

  3. added 3 commits that reference this issue on Dec 11, 2023
    6ada3b1
    e29bf03
    e62633d
  4. added a commit that references this issue on Sep 27, 2024
    48b2250
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions