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

Fix the sweeper monitor commit failures. #2040

Merged
merged 7 commits into from
Sep 11, 2024
Merged

Fix the sweeper monitor commit failures. #2040

merged 7 commits into from
Sep 11, 2024

Conversation

dbernstein
Copy link
Contributor

@dbernstein dbernstein commented Sep 6, 2024

Description

The Overdrive Sweeper monitor was failing because buried deep in the code was a commit() that was breaking the nested transactions used in the sweeper.

I removed the commit and used sqlalchemy'sexpire facility to ensure that objects were requerying the transactional state when necessary. expire simply requires that any subsequent access to the objects in the session context are refreshed with the latest known state within the transaction.

Motivation and Context

https://ebce-lyrasis.atlassian.net/browse/PP-1690

How Has This Been Tested?

I have manually tested the overdrive format sweep to ensure that it is working.

Checklist

  • I have updated the documentation accordingly.
  • All new and existing tests passed.

@dbernstein dbernstein marked this pull request as draft September 6, 2024 21:24
Copy link

codecov bot commented Sep 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.77%. Comparing base (08e6dc0) to head (e9d8e6e).
Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2040   +/-   ##
=======================================
  Coverage   90.77%   90.77%           
=======================================
  Files         342      342           
  Lines       40513    40511    -2     
  Branches     8770     8769    -1     
=======================================
  Hits        36774    36774           
+ Misses       2484     2483    -1     
+ Partials     1255     1254    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dbernstein dbernstein force-pushed the fix-sweep-monitor branch 2 times, most recently from ef9b67e to 2fee790 Compare September 10, 2024 17:15
lane = circulation_fixture.db.session.merge(lane)
session = circulation_fixture.db.session
lane = session.merge(lane)
session.expire_all()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This update was necessary to get the tests to pass in the ci environment. I was seeing a detached instance failure.

@@ -465,7 +466,8 @@ def test_get_items_from_query(self, novelist_fixture: NoveListFixture):

# Set up a book for this library.
edition = novelist_fixture.db.edition(
identifier_type=Identifier.ISBN, publication_date="2012-01-01"
identifier_type=Identifier.ISBN,
publication_date=dateutil.parser.parse("2012-01-01"),
Copy link
Contributor Author

@dbernstein dbernstein Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another side effect of removing that commit(). This one is a bit of a puzzler. I'm not sure how it worked in the first place. But maybe strings are automatically converted to date objects when committed?

@@ -123,7 +124,10 @@ def test_import(
assert "Feedbooks" == moby_dick_edition.data_source.name

assert "Test Publisher" == moby_dick_edition.publisher
assert datetime.date(2015, 9, 29) == moby_dick_edition.published
assert (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems to be a result of expiring the licensepool.

@@ -198,7 +199,10 @@ def test_opds2_importer_correctly_imports_valid_opds2_feed(
assert data.data_source == moby_dick_edition.data_source

assert "Test Publisher" == moby_dick_edition.publisher
assert datetime.date(2015, 9, 29) == moby_dick_edition.published
assert (
datetime.datetime(2015, 9, 29, tzinfo=tzutc())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

@@ -255,7 +259,10 @@ def test_opds2_importer_correctly_imports_valid_opds2_feed(
assert data.data_source == huckleberry_finn_edition.data_source

assert "Test Publisher" == huckleberry_finn_edition.publisher
assert datetime.date(2014, 9, 28) == huckleberry_finn_edition.published
assert (
datetime.datetime(2014, 9, 28, tzinfo=tzutc())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And same.

# to get LicensePool.delivery_mechanisms to notice that it's
# out of date.
if autocommit:
_db.commit()
Copy link
Contributor Author

@dbernstein dbernstein Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit buried deep in the code is deeply offensive. On the plus side, I appreciate the TODO note.

@@ -745,6 +744,8 @@ def _update_hold_end_date(
days=default_reservation_period
)

_db.expire_all()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least one unit test in the test_api.py tests was breaking because the holds collection associated with a patron was stale. This update fixed it. Surprisingly expiring the pool alone did not fix it.

@dbernstein dbernstein marked this pull request as ready for review September 10, 2024 18:45
@dbernstein dbernstein marked this pull request as draft September 10, 2024 19:54
@dbernstein dbernstein marked this pull request as ready for review September 11, 2024 00:23
@dbernstein dbernstein requested a review from a team September 11, 2024 03:56
Copy link
Contributor

@tdilauro tdilauro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! 🛠️

@dbernstein dbernstein merged commit 3784c8f into main Sep 11, 2024
20 checks passed
@dbernstein dbernstein deleted the fix-sweep-monitor branch September 11, 2024 15:24
@jonathangreen jonathangreen added the bug Something isn't working label Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants