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 constructing a Data Store with incomplete URL #224

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions spine_items/data_store/data_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,14 @@ def __init__(self, name, description, x, y, toolbox, project, url):
self._purge_dialog = None
self._database_validator = DatabaseConnectionValidator(self)
db_map = self.get_db_map_for_ds()
# Notify db manager about the Data Stores in the project so it can notify abobut the dirtyness of them
# Notify db manager about the Data Stores in the project, so it can notify about the dirtiness of them
self._toolbox.db_mngr.add_data_store_db_map(db_map, self)

def get_db_map_for_ds(self):
"""Returns the db map for the Data Store"""
if self._url.get("dialect"):
return self._toolbox.db_mngr.get_db_map(self.sql_alchemy_url(), self._logger, codename=self.name)
sa_url = self.sql_alchemy_url()
if sa_url is not None:
return self._toolbox.db_mngr.get_db_map(sa_url, self._logger, codename=self.name)
return None

@staticmethod
Expand All @@ -99,9 +100,9 @@ def parse_url(self, url):
"""Return a complete url dictionary from the given dict or string"""
base_url = {"dialect": "", "username": "", "password": "", "host": "", "port": "", "database": "", "schema": ""}
if isinstance(url, dict):
if url.get("dialect") == "sqlite" and "database" in url and url["database"] is not None:
if url.get("dialect") == "sqlite" and (database := url.get("database")):
# Convert relative database path back to absolute
url["database"] = os.path.abspath(os.path.join(self._project.project_dir, url["database"]))
url["database"] = os.path.abspath(os.path.join(self._project.project_dir, database))
for key, value in url.items():
if value is not None:
base_url[key] = value
Expand Down Expand Up @@ -545,5 +546,6 @@ def tear_down(self):
"""See base class"""
self._database_validator.wait_for_finish()
db_map = self.get_db_map_for_ds()
self._toolbox.db_mngr.remove_data_store_db_map(db_map, self)
if db_map is not None:
self._toolbox.db_mngr.remove_data_store_db_map(db_map, self)
super().tear_down()