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

Use a optimistic approach when inserting data #155

Closed
wants to merge 1 commit into from

Conversation

sduenas
Copy link
Member

@sduenas sduenas commented Jun 26, 2018

This PR tries to fix the enhancement proposed in #151.

With this optimistic approach, no more queries to check whether an entity exists on the database are run prior to its insertion. The new procedure works as follows:

  • Try to insert an entity without checking whether it exists in the database or not.
  • If the entity exists, an IntegrityError or a FlushError will be raised.
  • Rollback the transaction
  • Catch this error and check if it is an error raised by a duplicate entry.
  • If that was the cause, handle the error and raise an AlreadyExistsError.

Some changes were needed in AlreadyExistsError exception to store the ID and the type of the duplicated entry.

@sduenas sduenas requested a review from valeriocos June 26, 2018 16:05
With this optimistic approach, no more queries to check
whether an entity exists on the database are run prior to
its insertion. The new procedure works as follows:

  * Try to insert an entity without checking whether it exists in
    the database or not.
  * If the entity exists, an IntegrityError or a FlushError will
    be raised.
  * Rollback the transaction
  * Catch this error and check if it is an error raised by a
    duplicate entry.
  * If that was the cause, handle the error and raise an
    `AlreadyExistsError`.

Some changes were needed in `AlreadyExistsError` exception to
store the ID and the type of the duplicated entry.
Copy link
Member

@valeriocos valeriocos left a comment

Choose a reason for hiding this comment

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

LGTM

@sduenas sduenas closed this in bca8f71 Jun 27, 2018
@sduenas sduenas deleted the optimistic-db branch June 27, 2018 16:12
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.

None yet

2 participants