Skip to content

Commit

Permalink
Fix state of transaction start
Browse files Browse the repository at this point in the history
This affects the case when compilation config is set on the client,
while a new command is compiled within a transaction. In this case, the
compiler will only use the state issued in the transaction start. Before
this fix, we didn't send state on transaction commands, so those config
was not in effect within transactions, even though each query did carry
the right config.
  • Loading branch information
fantix committed May 26, 2023
1 parent f1fa612 commit 297de72
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions edgedb/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ async def privileged_execute(
qc=execute_context.cache.query_cache,
output_format=protocol.OutputFormat.NONE,
allow_capabilities=enums.Capability.ALL,
state=(
execute_context.state.as_dict()
if execute_context.state else None
),
)

def is_in_transaction(self) -> bool:
Expand Down
15 changes: 15 additions & 0 deletions tests/test_async_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -1030,3 +1030,18 @@ async def test_dup_link_prop_name(self):
DROP TYPE test::dup_link_prop_name_p;
DROP TYPE test::dup_link_prop_name;
''')

async def test_transaction_state(self):
with self.assertRaisesRegex(edgedb.QueryError, "cannot assign to id"):
async for tx in self.client.transaction():
async with tx:
await tx.execute('''
INSERT test::Tmp { id := <uuid>$0, tmp := '' }
''', uuid.uuid4())

client = self.client.with_config(allow_user_specified_id=True)
async for tx in client.transaction():
async with tx:
await tx.execute('''
INSERT test::Tmp { id := <uuid>$0, tmp := '' }
''', uuid.uuid4())
15 changes: 15 additions & 0 deletions tests/test_sync_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,3 +868,18 @@ def test_sync_banned_transaction(self):
r'cannot execute transaction control commands',
):
self.client.execute('start transaction')

def test_transaction_state(self):
with self.assertRaisesRegex(edgedb.QueryError, "cannot assign to id"):
for tx in self.client.transaction():
with tx:
tx.execute('''
INSERT test::Tmp { id := <uuid>$0, tmp := '' }
''', uuid.uuid4())

client = self.client.with_config(allow_user_specified_id=True)
for tx in client.transaction():
with tx:
tx.execute('''
INSERT test::Tmp { id := <uuid>$0, tmp := '' }
''', uuid.uuid4())

0 comments on commit 297de72

Please sign in to comment.