Skip to content

Commit

Permalink
Always Create a New Gene Normalizer Instance
Browse files Browse the repository at this point in the history
This is to avoid instances where the database connection has been prematurely closed. Since the gene normalizer instance uses an internal abstract database class and we don't expect this operation to occur too often, it is simpler to just close the existing database connection ourselves and respawn the instance in cases where it already exists.
  • Loading branch information
bencap committed Oct 14, 2024
1 parent b872cf4 commit 7dc6ed0
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/dcd_mapping/lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,17 @@ class GeneNormalizerBuilder:
"""Singleton constructor for Gene Normalizer instance."""

def __new__(cls) -> QueryHandler:
"""Provide Gene Normalizer instance. Construct it if unavailable.
"""Provide Gene Normalizer instance. If an instance has already been
constructed, close its connection and provide a new one.
:return: singleton instance of ``QueryHandler`` for Gene Normalizer
"""
if not hasattr(cls, "instance"):
db = create_db()
q = QueryHandler(db)
cls.instance = q
if hasattr(cls, "instance"):
cls.instance.db.close_connection()
cls.instance = None

db = create_db()
cls.instance = QueryHandler(db)
return cls.instance


Expand Down

0 comments on commit 7dc6ed0

Please sign in to comment.