Skip to content

Commit

Permalink
You can now raise esorm.error.ConflictError to retry in retry_on_conf…
Browse files Browse the repository at this point in the history
…lict decorated functions and methods.
  • Loading branch information
wallneradam committed Nov 23, 2024
1 parent 5b73622 commit f476c50
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions esorm/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ class InvalidModelError(Exception):
"""


class ConflictError(Exception):
"""
Raised when a conflict occurs.
You can manually raise this to retry operation with `retry_on_conflict` decorator.
"""


class BulkOperationError(TypedDict):
"""
A dictionary type to represent an error in a bulk operation response from Elasticsearch.
Expand Down
4 changes: 2 additions & 2 deletions esorm/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from .utils import snake_case, utcnow
from .aggs import ESAggs, ESAggsResponse

from .error import InvalidResponseError, NotFoundError
from .error import InvalidResponseError, NotFoundError, ConflictError as ESORMConflictError
from .esorm import es, get_es_version
from .query import ESQuery
from .response import ESResponse
Expand Down Expand Up @@ -981,7 +981,7 @@ async def wrapper(*args, **kwargs):
while True:
try:
return await func(*args, **kwargs)
except ElasticConflictError:
except (ElasticConflictError, ESORMConflictError):
# Reload the document if it is a method of ESModel
if reload_on_conflict and isinstance(args[0], ESModel):
await args[0].reload()
Expand Down

0 comments on commit f476c50

Please sign in to comment.