Skip to content

Commit 7dc6ed0

Browse files
committed
Always Create a New Gene Normalizer Instance
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.
1 parent b872cf4 commit 7dc6ed0

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/dcd_mapping/lookup.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,17 @@ class GeneNormalizerBuilder:
162162
"""Singleton constructor for Gene Normalizer instance."""
163163

164164
def __new__(cls) -> QueryHandler:
165-
"""Provide Gene Normalizer instance. Construct it if unavailable.
165+
"""Provide Gene Normalizer instance. If an instance has already been
166+
constructed, close its connection and provide a new one.
166167
167168
:return: singleton instance of ``QueryHandler`` for Gene Normalizer
168169
"""
169-
if not hasattr(cls, "instance"):
170-
db = create_db()
171-
q = QueryHandler(db)
172-
cls.instance = q
170+
if hasattr(cls, "instance"):
171+
cls.instance.db.close_connection()
172+
cls.instance = None
173+
174+
db = create_db()
175+
cls.instance = QueryHandler(db)
173176
return cls.instance
174177

175178

0 commit comments

Comments
 (0)