From 3a1d5f69ed3655f3b05dc48f4f478700af93c270 Mon Sep 17 00:00:00 2001 From: Bram Jans Date: Tue, 4 Nov 2025 10:38:11 +0100 Subject: [PATCH] refactor: Use WORKSPACE_DATABASE_URL for workspace.database_url To allow the main OH app to set it as it pleases for pipeline runs. Fallback to the regular constructed URL. --- openhexa/sdk/workspaces/current_workspace.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/openhexa/sdk/workspaces/current_workspace.py b/openhexa/sdk/workspaces/current_workspace.py index 8a1b687a..0d62480e 100644 --- a/openhexa/sdk/workspaces/current_workspace.py +++ b/openhexa/sdk/workspaces/current_workspace.py @@ -184,10 +184,15 @@ def database_url(self): The URL follows the official PostgreSQL specification. (See https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING for more information) """ - return ( - f"postgresql://{self.database_username}:{self.database_password}" - f"@{self.database_host}:{self.database_port}/{self.database_name}" - ) + try: + # First try the environment variable. In case we're inside a pipeline, + # we add some extra parameters to the URL. + return os.environ.get("WORKSPACE_DATABASE_URL") + except KeyError: + return ( + f"postgresql://{self.database_username}:{self.database_password}" + f"@{self.database_host}:{self.database_port}/{self.database_name}" + ) @property def files_path(self) -> str: