All jobs

Fix "ArgumentError: Column expression, FROM clause, or other columns clause element expected" on SQLAlchemy 2

Yes. An agent finds every select([...]) list and the other 1.x calls behind it, ports the module to the 2.0 style, and runs the project's own tests on 1.4 and 2.x.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

SQLAlchemy 2.0 dropped the list form of select. Code written as select([table.c.name], table.c.id == key) raises ArgumentError: Column expression, FROM clause, or other columns clause element expected, got [Column(...)]. Did you mean to say select(Column(...))? the first time it builds a query. It rarely arrives alone: the same release removed Engine.execute, Table.count(), the positional where-clause on delete(), positional values on insert(), the encoding argument of create_engine, and plain strings as statements, and each surfaces as a different exception as soon as the one before it is fixed.

A library like FedericoCeratto/bottle-cork shows the whole set in one file. cork/sqlalchemy_backend.py wraps three tables in a SqlTable class: __contains__ and __getitem__ build select([self._key_col], self._key_col == key) and select([self._table], self._key_col == key), __iter__ and iteritems use select([self._key_col]) and select([self._table]), __len__ calls self._table.count(), pop calls delete(self._table, self._key_col == key), insert calls self._table.insert(d), and all thirteen database calls go through self._engine.execute. SqlAlchemyBackend.__init__ calls create_engine(db_url, encoding="utf-8") and executes CREATE DATABASE and USE as bare strings. The repository has a real test suite: tests/test_functional.py runs every backend test against an in-memory SQLite engine built with SqlAlchemyBackend("sqlite:///:memory:", initialize=True), 78 tests under -k sqlalchemy.

The agent installs the project with three SQLAlchemy releases in three environments and runs that selection in each. On 1.3.24 all 78 pass, which is the baseline. On 1.4.54 the first failure is 'Table' object has no attribute 'count', and with SQLALCHEMY_WARN_20=1 the warnings name Engine.execute, implicit autocommit and the string statement, which is the removal list written out by the library itself. On the current 2.x release the very first call fails earlier, in create_engine with the encoding argument; remove that and the error from the title appears on the first select, followed in turn by the count, delete, insert and Engine.execute failures. The agent records each one with its line.

Then it ports the module in one pass: select(col).where(...) and select(table).where(...), select(func.count()).select_from(table) for the length, delete(table).where(...), table.insert().values(d), text() around the two raw strings, and every execute moved inside with engine.begin() as conn, which also replaces the autocommit the 1.x engine did silently. Reads of a row by column name become row._mapping[...], since a 2.0 Row is a tuple. It reruns the selection: on 1.4 every test passes, so the port is safe to merge before the pin moves, and on 2.x the remaining failures are the ones the agent lists, a test that itself calls engine.execute and a code path that still reads a popped row like a dictionary. It fixes those the same way, states the new lower bound, 1.4, that the ported module needs, and notes that 1.3 is left behind.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "This project fails on SQLAlchemy 2 with ArgumentError: Column expression, FROM clause, or other columns clause element expected. Port it to the 2.0 style and prove it with the project's own tests. In three clean virtual environments install the project with SQLAlchemy 1.3, 1.4 and the current 2.x release, run the tests that use the SQLAlchemy backend in each, and report the first failure per environment with its file and line; on 1.4 also run with SQLALCHEMY_WARN_20=1 and list the distinct RemovedIn20 warnings. Find every select with a list argument, every Engine.execute, Table.count, positional where-clause on delete, positional values on insert, string statement and removed create_engine argument. Port them: select(...).where(...), select(func.count()).select_from(...), delete(...).where(...), insert().values(...), text() for raw SQL, and connections opened with engine.begin() so writes commit as they did under autocommit. Read rows through row._mapping where the code indexed them by column name. Rerun the tests on 1.4 and on 2.x after the port and report both counts; fix any test that itself uses a removed API, and say which. State the lowest SQLAlchemy the ported module supports and set it as the lower bound in the project's dependency declaration. Open a pull request with the three before-counts, the two after-counts and the diff.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

A pull request that rewrites the backend module and raises the SQLAlchemy lower bound in the project's dependency declaration. The description opens with a table of three environments, the SQLAlchemy release in each, the first failure and its line, and for 1.4 the distinct RemovedIn20Warning messages, so a reviewer sees that the title error is one item on a list the library itself published.

Below that is the port as a table of old form to new form, one row per construct, with the count of sites each touched, and then the test counts after the change: the full selection passing on 1.4, and on 2.x the same count once the two leftovers are handled, with the leftovers named. The session's record keeps every test run.

What a reviewer checks before merging is transaction behaviour. Under 1.x the engine committed each statement on its own; the port commits per engine.begin() block, which is the same for single statements and tighter for the few methods that run two. The description points at those methods so the reviewer can confirm nothing relied on a half-committed pair.

Run it on every Linear issue labelled sqlalchemy-2

The 2.0 port is work teams schedule rather than discover, so a label is the right trigger. Create an automation in the Project that holds the repository, save this prompt, and add a linear trigger with labels set to sqlalchemy-2. The trigger needs a Linear connection for the member the automation runs as, made in the console under Settings → Connections. When a person in your Rush org adds the label, a run starts with the saved prompt and the issue placed after it as the event.

The saved prompt is the only instruction, so word the issue to name the module or package to port and nothing more. A label added by an app integration does not fire the trigger. The pull request link comes back on the session, and the automation's max runs per hour keeps a bulk relabel from starting dozens of ports at once.

The use case this job follows, with its automation and trigger: Fix a bug from an alert.

Why run it on Rush?

This port is judged by a test suite run three times on three library versions, and the question is not whether the new code is right but whether the old code's behaviour survived, including the autocommit nobody wrote down. A Rush sandbox holds the three environments side by side and the session keeps every run, so the pull request carries counts that a reviewer can compare rather than a claim that it works now.

It also turns a chain of one-at-a-time exceptions into a single list. Each removed construct hides the next until it is fixed, which on a laptop becomes an afternoon of running, failing and editing. The agent reads the warnings the 1.4 release emits, fixes the whole list in one pass, and reports the two leftovers it found by running the tests rather than by reading.

Frequently asked questions

Why does the error point at select when I also use engine.execute?

Because the query is built before it is executed. select([...]) raises while constructing the statement, so Engine.execute on the next line is never reached. Fix the select and the AttributeError for execute appears. The agent lists the whole chain so the pull request handles it in one pass.

Can I port in place and keep supporting SQLAlchemy 1.3?

No. The 2.0-style select(col) call is itself rejected by 1.3, which wants the list, so a module cannot satisfy both. 1.4 accepts both styles and is the bridge: the agent proves the port on 1.4 first and sets 1.4 as the lower bound.

What replaces engine.execute?

A connection: with engine.begin() as conn: conn.execute(stmt) commits at the end of the block, matching what the 1.x engine's autocommit did for single statements. engine.connect() without begin() needs an explicit commit(). Raw SQL strings must be wrapped in text().

Why do row reads change?

In 2.0 a Row behaves like a named tuple, so row["name"] and row[table.c.name] no longer work; row._mapping[...] does, and row.name does for attribute access. Code that passes rows to callers expecting dictionaries needs the conversion at the boundary, which is where the agent found one of the two leftovers.

Does the agent run my tests against MySQL or PostgreSQL?

It runs whatever the suite runs without a server, which for most projects is the SQLite path. Tests parameterised over a live database are reported as skipped or as not run, not as passing. The pull request says which backends the counts cover.

More SQLAlchemy jobs

More jobs like this: Fix a bug from an alert

Keep reading