Skip to content

Commit

Permalink
Fix generation of dummy_pathid in nonconflict ctes (#3848)
Browse files Browse the repository at this point in the history
Since the relevant rel wasn't in the hierarchy, the search for the
enclosing volatility ref wasn't succeeding, and when nonconflict CTEs
were used in a for loop, sometimes things could get
duplicated. (Depending on the vagaries of how pg orders the loops, I
think).

Fixes #3847.
  • Loading branch information
msullivan committed May 10, 2022
1 parent f06bec5 commit 5248eb9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 4 additions & 3 deletions edb/pgsql/compiler/dml.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,9 +880,10 @@ def compile_insert_else_body(
name_hint=sn.QualName(
module='__derived__',
name=ctx.env.aliases.get('dummy'))))
dummy_q = pgast.SelectStmt()
relctx.ensure_transient_identity_for_path(
dummy_pathid, dummy_q, ctx=ictx)
with ctx.subrel() as dctx:
dummy_q = dctx.rel
relctx.ensure_transient_identity_for_path(
dummy_pathid, dummy_q, ctx=dctx)
dummy_rvar = relctx.rvar_for_rel(
dummy_q, lateral=True, ctx=ictx)
relctx.include_rvar(ictx.rel, dummy_rvar,
Expand Down
13 changes: 13 additions & 0 deletions tests/test_edgeql_insert.py
Original file line number Diff line number Diff line change
Expand Up @@ -3103,6 +3103,19 @@ async def test_edgeql_insert_unless_conflict_23(self):
self.assertEqual(len(obj3), 1)
self.assertEqual(obj1.id, tuple(obj3)[0].id)

async def test_edgeql_insert_unless_conflict_24(self):
await self.con.execute('''
WITH
raw_data := to_json('[1,2]')
for data in {<int64>json_array_unpack(raw_data)} union(
INSERT Person {
note := (INSERT Note { name := 'x' }),
name := <str>data,
}
UNLESS conflict on .name
);
''')

async def test_edgeql_insert_dependent_01(self):
query = r'''
SELECT (
Expand Down

0 comments on commit 5248eb9

Please sign in to comment.