Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ dependencies = [
"ga4gh.vrs >=2.1.3,<3.0",
"wags-tails ~= 0.4.0",
"bioutils",
"pip",
]
dynamic = ["version"]

Expand Down
9 changes: 6 additions & 3 deletions src/cool_seq_tool/resources/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
import logging
from collections import namedtuple
from pathlib import Path
from urllib.parse import urlparse

from agct._core import ChainfileError
from asyncpg import InvalidCatalogNameError, UndefinedTableError
from biocommons.seqrepo import SeqRepo
from pip._internal.utils.misc import redact_auth_from_url

from cool_seq_tool.handlers.seqrepo_access import SEQREPO_ROOT_DIR, SeqRepoAccess
from cool_seq_tool.mappers.liftover import LiftOver
from cool_seq_tool.resources.data_files import DataFile, get_data_file
from cool_seq_tool.sources.uta_database import UTA_DB_URL, UtaDatabase
from cool_seq_tool.sources.uta_database import UTA_DB_URL, ParseResult, UtaDatabase

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -120,9 +120,12 @@ async def check_status(
else:
status["liftover"] = True

sanitized_url = redact_auth_from_url(UTA_DB_URL)
try:
parsed_result = ParseResult(urlparse(db_url))
sanitized_url = parsed_result.sanitized_url
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this line has to be outside the try, otherwise it's not in-scope for the except statements.

await UtaDatabase.create(db_url)
except ValueError:
_logger.exception("Database URL is not valid")
except (OSError, InvalidCatalogNameError, UndefinedTableError):
_logger.exception(
"Encountered error instantiating UTA at URI %s", sanitized_url
Expand Down
16 changes: 15 additions & 1 deletion src/cool_seq_tool/sources/uta_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from os import environ
from typing import Any, Literal, TypeVar
from urllib.parse import ParseResult as UrlLibParseResult
from urllib.parse import quote, unquote, urlparse
from urllib.parse import quote, unquote, urlparse, urlunparse

import asyncpg
import boto3
Expand Down Expand Up @@ -954,3 +954,17 @@ def schema(self) -> str | None:
"""Create schema property."""
path_elems = self.path.split("/")
return path_elems[2] if len(path_elems) > 2 else None

@property
def sanitized_url(self) -> str:
"""Sanitized DB URL with the password masked"""
return urlunparse(
(
self.scheme,
self.username,
self.hostname,
self.port,
self.database,
self.schema,
)
)
Comment on lines 958 to 981
Copy link
Contributor

@zealws zealws Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You really need to put some unit-tests on this, cause this won't work at all.

>>> url
'postgresql://uta_admin:localdev@localhost:5432/uta/uta_20241220'

>>> r = ParseResult(urlparse(url))
>>> r
ParseResult(scheme='postgresql', netloc='uta_admin:localdev@localhost:5432', path='/uta/uta_20241220', params='', query='', fragment='')

>>> r.sanitized_url
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    import platform
  File "/Users/zxw016/dev/wagner/cool-seq-tool/src/cool_seq_tool/sources/uta_database.py", line 961, in sanitized_url
    return urlunparse(
        (
    ...<6 lines>...
        )
    )
  File "/Users/zxw016/.pyenv/versions/3.13.5/lib/python3.13/urllib/parse.py", line 531, in urlunparse
    _coerce_args(*components))
    ~~~~~~~~~~~~^^^^^^^^^^^^^
  File "/Users/zxw016/.pyenv/versions/3.13.5/lib/python3.13/urllib/parse.py", line 130, in _coerce_args
    raise TypeError("Cannot mix str and non-str arguments")
TypeError: Cannot mix str and non-str arguments

Notes:

  1. We want to preserve the **** in the URL, but only if the password was non-empty to begin with.
  2. You need to reconstruct a named tuple that looks like the return value of urlparse.
  3. The port is an integer, which is what causes the exception above. This is fixed by using a named tuple.
  4. The database and schema shouldn't be embedded in the URL directly. They were parsed from self.path and so you should use the self.path instead.