Skip to content

Commit

Permalink
[PP-1956] Ensure the context transaction manager is being used for cr…
Browse files Browse the repository at this point in the history
…eating identifiers in SweepMonitor runs.
  • Loading branch information
dbernstein committed Nov 20, 2024
1 parent 1d1b4eb commit 199fc5d
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/palace/manager/api/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ def update_book(
# NOTE: availability is bibliographic.circulation, so it's a
# little redundant to call availability.apply() -- it's taken
# care of inside bibliographic.apply().
bibliographic.apply(edition, self.collection, replace=policy)
bibliographic.apply(edition, self.collection, replace=policy, db=self._db)
availability.apply(self._db, self.collection, replace=policy)
return edition, new_edition, license_pool, new_license_pool

Expand Down
5 changes: 4 additions & 1 deletion src/palace/manager/api/bibliotheca.py
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,10 @@ def _process_metadata(
edition, _ = metadata.edition(self._db)

metadata.apply(
edition, collection=self.collection, replace=self.replacement_policy
edition,
collection=self.collection,
replace=self.replacement_policy,
db=self._db,
)


Expand Down
2 changes: 1 addition & 1 deletion src/palace/manager/api/overdrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -1725,7 +1725,7 @@ def update_formats(self, licensepool):
edition, ignore = self._edition(licensepool)

replace = ReplacementPolicy.from_license_source(self._db)
metadata.apply(edition, self.collection, replace=replace)
metadata.apply(edition, self.collection, replace=replace, db=self._db)

def update_licensepool(self, book_id):
"""Update availability information for a single book.
Expand Down
14 changes: 10 additions & 4 deletions src/palace/manager/core/metadata_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,7 @@ def apply(
data_source=data_source,
media_type=link.media_type,
content=link.content,
db=_db,
)
link_objects[link] = link_obj

Expand Down Expand Up @@ -1436,6 +1437,7 @@ def apply(
replace_formats=False,
replace_rights=False,
force=False,
db=None,
):
"""Apply this metadata to the given edition.
Expand All @@ -1445,8 +1447,10 @@ def apply(
New: If contributors changed, this is now considered a core change,
so work.simple_opds_feed refresh can be triggered.
"""
_db = Session.object_session(edition)

if not db:
_db = Session.object_session(edition)
else:
_db = db
# If summary, subjects, or measurements change, then any Work
# associated with this edition will need a full presentation
# recalculation.
Expand Down Expand Up @@ -1637,6 +1641,7 @@ def _key(classification):
rights_explanation=link.rights_explanation,
original_resource=original_resource,
transformation_settings=link.transformation_settings,
db=_db,
)
if link.rel in self.REL_REQUIRES_NEW_PRESENTATION_EDITION:
work_requires_new_presentation_edition = True
Expand Down Expand Up @@ -1717,7 +1722,7 @@ def _key(classification):
elif link.thumbnail:
# We need to make sure that its thumbnail exists locally and
# is associated with the original image.
self.make_thumbnail(data_source, link, link_obj)
self.make_thumbnail(_db, data_source, link, link_obj)

# Make sure the work we just did shows up.
made_changes = edition.calculate_presentation(
Expand Down Expand Up @@ -1757,7 +1762,7 @@ def _key(classification):

return edition, work_requires_new_presentation_edition

def make_thumbnail(self, data_source, link, link_obj):
def make_thumbnail(self, _db, data_source, link, link_obj):
"""Make sure a Hyperlink representing an image is connected
to its thumbnail.
"""
Expand All @@ -1782,6 +1787,7 @@ def make_thumbnail(self, data_source, link, link_obj):
data_source=data_source,
media_type=thumbnail.media_type,
content=thumbnail.content,
db=_db,
)
# And make sure the thumbnail knows it's a thumbnail of the main
# image.
Expand Down
6 changes: 5 additions & 1 deletion src/palace/manager/sqlalchemy/model/identifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,7 @@ def add_link(
rights_explanation=None,
original_resource=None,
transformation_settings=None,
db=None,
):
"""Create a link between this Identifier and a (potentially new)
Resource.
Expand All @@ -769,7 +770,10 @@ def add_link(
Resource,
)

_db = Session.object_session(self)
if not db:
_db = Session.object_session(self)
else:
_db = db
# Find or create the Resource.
if not href:
href = Hyperlink.generic_uri(data_source, self, rel, content)
Expand Down
2 changes: 2 additions & 0 deletions src/palace/manager/sqlalchemy/model/licensing.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ def add_link(
rights_explanation=None,
original_resource=None,
transformation_settings=None,
db=None,
):
"""Add a link between this LicensePool and a Resource.
Expand Down Expand Up @@ -689,6 +690,7 @@ def add_link(
rights_explanation,
original_resource,
transformation_settings,
db,
)

def needs_update(self):
Expand Down

0 comments on commit 199fc5d

Please sign in to comment.