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

Handle store error during finalize #958

Merged
merged 1 commit into from
May 30, 2024

Conversation

jmmshn
Copy link
Contributor

@jmmshn jmmshn commented May 29, 2024

Handle store Error during finalize

I assume the try/except in finalize is meant to handle situations where the store is already closed.

def finalize(self):
"""
Perform any final clean up.
"""
# Close any Mongo connections.
for store in self.sources + self.targets:
try:
store.close()
except AttributeError:
continue

However, closing a store:

def close(self):
"""Close up all collections."""
self._collection.database.client.close()
self._coll = None
if self.ssh_tunnel is not None:
self.ssh_tunnel.stop()

can cause a StoreError if it's already closed.

def _collection(self):
"""Property referring to underlying pymongo collection."""
if self._coll is None:
raise StoreError("Must connect Mongo-like store before attempting to use it")
return self._coll

Copy link

codecov bot commented May 29, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 81.31%. Comparing base (f88951d) to head (819d187).

Files Patch % Lines
src/maggma/core/builder.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #958   +/-   ##
=======================================
  Coverage   81.31%   81.31%           
=======================================
  Files          46       46           
  Lines        3976     3976           
=======================================
  Hits         3233     3233           
  Misses        743      743           

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

@rkingsbury rkingsbury merged commit 5a502f0 into materialsproject:main May 30, 2024
8 of 9 checks passed
@rkingsbury
Copy link
Collaborator

Thanks @jmmshn !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants