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

[PP-1956] Ensure the context transaction manager is being used for cr… #2181

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[PP-1956] Ensure the context transaction manager is being used for cr…
…eating identifiers in SweepMonitor runs.
  • Loading branch information
dbernstein committed Nov 20, 2024
commit 199fc5ddf97b354055268f4b48f818964d71c521
2 changes: 1 addition & 1 deletion src/palace/manager/api/axis.py
Original file line number Diff line number Diff line change
@@ -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

5 changes: 4 additions & 1 deletion src/palace/manager/api/bibliotheca.py
Original file line number Diff line number Diff line change
@@ -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,
)


2 changes: 1 addition & 1 deletion src/palace/manager/api/overdrive.py
Original file line number Diff line number Diff line change
@@ -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.
14 changes: 10 additions & 4 deletions src/palace/manager/core/metadata_layer.py
Original file line number Diff line number Diff line change
@@ -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

@@ -1436,6 +1437,7 @@ def apply(
replace_formats=False,
replace_rights=False,
force=False,
db=None,
):
"""Apply this metadata to the given edition.

@@ -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.
@@ -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
@@ -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(
@@ -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.
"""
@@ -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.
6 changes: 5 additions & 1 deletion src/palace/manager/sqlalchemy/model/identifier.py
Original file line number Diff line number Diff line change
@@ -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.
@@ -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)
2 changes: 2 additions & 0 deletions src/palace/manager/sqlalchemy/model/licensing.py
Original file line number Diff line number Diff line change
@@ -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.

@@ -689,6 +690,7 @@ def add_link(
rights_explanation,
original_resource,
transformation_settings,
db,
)

def needs_update(self):