Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add savepoint API #433

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Add savepoint API #433

wants to merge 4 commits into from

Conversation

fantix
Copy link
Member

@fantix fantix commented May 25, 2023

Please see tests for use case.

  • Add docs

Fixes #407

with self.assertRaisesRegex(
edgedb.InterfaceError, "savepoint.*already exists"
):
await tx.declare_savepoint("sp1")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is contrary to server savepoint semantics, masking an earlier savepoint is allowed:

edgedb> start transaction;
OK: START TRANSACTION
edgedb[tx]> declare savepoint sp1;
OK: DECLARE SAVEPOINT
edgedb[tx]> declare savepoint sp1;
OK: DECLARE SAVEPOINT

Copy link
Contributor

@tailhook tailhook May 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This releases previous savepoint with that name, right?
Not it doesn't. It creates a nested one with that name. And then you have to release twice.

So releasing the one that was created first should release inner, to have correct semantics.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think Paul is right.

Copy link
Contributor

@tailhook tailhook left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Three questions:

  1. Why do we skip context API: with tx.declare_savepoint("name") entirely?
  2. We should allow skipping name argument and generate something unique (e.g. uuid). Actually while we have variables in python (I mean sp_name = conn.declare_savepoint() ) names are useless, will only provoke unexpected conflicts.
  3. Do we need declare_ part? x = tx.savepoint() is nice, no? (we already do that with transactions by skipping start part)

Context API fits in pretty nicely, even with rollback (since rollback and release aren't mutually exclusive):

with tx.savepoint() as sp:
  # do something
  if was_already_applied:
      sp.rollback()

It can be added later, but is pretty uncontroversial I think.

with self.assertRaisesRegex(
edgedb.InterfaceError, "savepoint.*already exists"
):
await tx.declare_savepoint("sp1")
Copy link
Contributor

@tailhook tailhook May 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This releases previous savepoint with that name, right?
Not it doesn't. It creates a nested one with that name. And then you have to release twice.

So releasing the one that was created first should release inner, to have correct semantics.

@1st1
Copy link
Member

1st1 commented May 31, 2023

We should allow skipping name argument and generate something unique (e.g. uuid). Actually while we have variables in python (I mean sp_name = conn.declare_savepoint() ) names are useless, will only provoke unexpected conflicts.

+1

Do we need declare_ part? x = tx.savepoint() is nice, no? (we already do that with transactions by skipping start part)

Yes, please, it should be tx.savepoint() with an optional name argument (although I'd not even have the name argument at all, why would you want it?)

@fantix
Copy link
Member Author

fantix commented Jun 27, 2023

Pushed a fix to rename declare_savepoint() to savepoint() and dropped user-defined names (always use s + uuid instead).

(Context API) can be added later, but is pretty uncontroversial I think.

Let's add later 😏

@jsimonlane
Copy link

Hi all, any updates on this?

@fantix
Copy link
Member Author

fantix commented Nov 19, 2023

Hi all, any updates on this?

Sorry, not yet. But we'll put time into the Python binding very soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Transaction savepoints are essential
5 participants