Skip to content

[Refactor] Represent transactions in a separate typestate + contextmanager #209

Open
@mitchhentges

Description

@mitchhentges

Instead of having a mutable EditService and having checks before operation to assert state (which is what we're doing relatively ergonomically with this @transaction_required annotation), we could utilize typestates. So, you'll call a function to start the transaction, and you'll receive a transaction object that can perform all the operations (and commit at the end).

This way, it's easier to use this API, since you don't have functions on your objects that have implicit requirements - you physically can't call transaction functions until you've started the transaction. Additionally, there's less room for errors when changing the API, such as forgetting the @transaction_required annotation, since required resources (like edit_id) would sit in the transaction object.

Additionally, by making the transaction object work with a context manager, we can have automatic committing when exiting a with ... block, which would make this even better

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions