From 6b966e38293492342525e44c44fb39a5f29ca9c4 Mon Sep 17 00:00:00 2001 From: Daniel Bernstein Date: Wed, 18 Dec 2024 10:02:06 -0800 Subject: [PATCH] Fix format sweep script by ensuring all operations within the context manager are performed on the same session. --- src/palace/manager/api/circulation.py | 1 + src/palace/manager/core/metadata_layer.py | 1 + src/palace/manager/sqlalchemy/model/licensing.py | 8 +++++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/palace/manager/api/circulation.py b/src/palace/manager/api/circulation.py index b7e423da0..d33bf4136 100644 --- a/src/palace/manager/api/circulation.py +++ b/src/palace/manager/api/circulation.py @@ -184,6 +184,7 @@ def apply( self.drm_scheme, self.rights_uri, self.resource, + db=_db, ) loan.fulfillment = lpdm return lpdm diff --git a/src/palace/manager/core/metadata_layer.py b/src/palace/manager/core/metadata_layer.py index 074caeaf6..27509b8d6 100644 --- a/src/palace/manager/core/metadata_layer.py +++ b/src/palace/manager/core/metadata_layer.py @@ -996,6 +996,7 @@ def apply( format.drm_scheme, format.rights_uri or self.default_rights_uri, resource, + db=_db, ) new_lpdms.append(lpdm) diff --git a/src/palace/manager/sqlalchemy/model/licensing.py b/src/palace/manager/sqlalchemy/model/licensing.py index 33f13ffe2..d19c7cdb3 100644 --- a/src/palace/manager/sqlalchemy/model/licensing.py +++ b/src/palace/manager/sqlalchemy/model/licensing.py @@ -1557,6 +1557,7 @@ def set( drm_scheme, rights_uri, resource=None, + db=None, ) -> LicensePoolDeliveryMechanism: """Register the fact that a distributor makes a title available in a certain format. @@ -1571,7 +1572,12 @@ def set( :param resource: A Resource representing the book itself in a freely redistributable form. """ - _db = Session.object_session(data_source) + + if db: + _db = db + else: + _db = Session.object_session(data_source) + delivery_mechanism, ignore = DeliveryMechanism.lookup( _db, content_type, drm_scheme )