[19.0][FIX] stock_account: fix syntax error in stock_move_value() post-migration on PostgreSQL 13 - #5903
Merged
pedrobaeza merged 1 commit intoAug 11, 2026
Conversation
…ation on PostgreSQL 13
stock_move_value() in stock_account/19.0.1.1/post-migration.py builds an
UPDATE ... FROM (SELECT ... sum(value) value ...) aggregate subquery with
a bare-word column alias (no AS) immediately after the aggregate call.
PostgreSQL 13 rejects this as a syntax error:
ERROR: syntax error at or near "value"
LINE 5: move_id, sum(value) value
^
PostgreSQL 16 accepts the same statement, which is why this is easy to
miss when re-testing on a newer engine — it is PostgreSQL-version
dependent, not data-dependent. Any 18.0 -> 19.0 migration of a database
with stock_account installed, run against a PostgreSQL 13 backend, hits
this unconditionally partway through the post-migration step.
Fix: alias the aggregate column explicitly (agg_value) and reference the
aliased name in the outer UPDATE ... SET, instead of relying on the bare
column name colliding with the outer table's own value column.
Found and reproduced during a real 15.0 -> 19.0 OpenUpgrade migration
(PostgreSQL 13 source engine). Confirmed the exact failing statement
against a live PostgreSQL 13.23 database inside a BEGIN;...ROLLBACK; and
confirmed the patched statement runs clean against the same database.
pedrobaeza
approved these changes
Aug 11, 2026
pedrobaeza
left a comment
Member
There was a problem hiding this comment.
Although using so old PG version in 19 is not recommended, this works for all the PG versions, so it's harmless.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
stock_move_value()inopenupgrade_scripts/scripts/stock_account/19.0.1.1/post-migration.pybuilds an aggregate subquery with a bare-word column alias (no
AS) immediatelyafter the
sum()call:PostgreSQL 13 rejects this as a syntax error:
This is PostgreSQL-version dependent, not data-dependent — the same statement
runs fine on PostgreSQL 16 (confirmed below), which makes the bug easy to miss
when re-testing on a newer engine. Any
18.0 -> 19.0migration of a databasewith
stock_accountinstalled, run against a PostgreSQL 13 backend, hits thisunconditionally partway through the post-migration step.
Repro (real, not assumed)
Against a PostgreSQL 13.23 database used for an actual
15.0 -> 19.0OpenUpgrade migration chain, inside
BEGIN; ... ROLLBACK;so nothing persisted:The same statement, patched (
agg_valuealias), against the same database,in the same rollback-guarded transaction:
A separate check against a PostgreSQL 16 database did not reproduce the
error — confirming this is version-dependent, not something wrong with the
data.
Fix
Alias the aggregate column explicitly (
agg_value) and reference the aliasedname in the outer
UPDATE ... SET, instead of relying on a bare column namethat happens to collide with the outer table's own
valuecolumn:Test
python3 -m py_compileon the patched file compiles clean.ruff check/ruff format --checkon the patched file both pass with no findings. Thepatched SQL statement was run against the same PostgreSQL 13.23 database
used for the repro above (again inside
BEGIN;...ROLLBACK;) and completedwith
UPDATE 3, no error.No functional/behavioral test suite covers this migration script beyond
OpenUpgrade's own migration-execution smoke test, so this fix was verified
by direct SQL execution against a real PostgreSQL 13 database reproducing
the exact failure, per the repro above — not merely reasoned about.