Skip to content

Commit

Permalink
Fix uncommitted nested transaction in SweepMonitor (#2074)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathangreen authored Sep 18, 2024
1 parent 4440345 commit 557663c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 20 deletions.
7 changes: 1 addition & 6 deletions src/palace/manager/api/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,7 @@ def catch_up_from(
def process_book(
self, bibliographic: Metadata, circulation: CirculationData
) -> tuple[Edition, LicensePool]:
tx = self._db.begin_nested()
try:
with self._db.begin_nested():
edition, new_edition, license_pool, new_license_pool = self.api.update_book(
bibliographic, circulation
)
Expand All @@ -807,11 +806,7 @@ def process_book(
self.bibliographic_coverage_provider.handle_success(identifier)
self.bibliographic_coverage_provider.add_coverage_record_for(identifier)

tx.commit()
return edition, license_pool
except Exception as e:
tx.rollback()
raise e


class Axis360BibliographicCoverageProvider(BibliographicCoverageProvider):
Expand Down
15 changes: 6 additions & 9 deletions src/palace/manager/api/overdrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -2009,16 +2009,13 @@ def catch_up_from(self, start, cutoff, progress: TimestampData):
)
def process_book(self, book, progress):
# Attempt to create/update the book up to MAXIMUM_BOOK_RETRIES times.
book_changed = False
tx = self._db.begin_nested()
try:
_, _, is_changed = self.api.update_licensepool(book)
tx.commit()
book_changed = is_changed
except Exception as e:
self.log.exception("exception on update_licensepool: ", exc_info=e)
tx.rollback()
raise e
with self._db.begin_nested():
_, _, is_changed = self.api.update_licensepool(book)
book_changed = is_changed
except Exception:
self.log.exception("exception on update_licensepool: ")
raise
return book_changed

def should_stop(self, start, api_description, is_changed):
Expand Down
6 changes: 1 addition & 5 deletions src/palace/manager/core/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,7 @@ def run_once(self, *ignore):
)
def process_batch(self, offset):
"""Process one batch of work."""
tx = self._db.begin_nested()
try:
with self._db.begin_nested():
offset = offset or 0
items = self.fetch_batch(offset).all()
if items:
Expand All @@ -538,9 +537,6 @@ def process_batch(self, offset):
result = (0, 0)

return result
except Exception as e:
tx.rollback()
raise e

def process_items(self, items):
"""Process a list of items."""
Expand Down

0 comments on commit 557663c

Please sign in to comment.