Skip to content

Commit

Permalink
Merge pull request #366 from chaen/oracle_url
Browse files Browse the repository at this point in the history
Allow for oracle+oracledb_async URL
  • Loading branch information
chrisburr authored Jan 13, 2025
2 parents e5103f6 + 88988b9 commit 3ddb10f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion diracx-core/src/diracx/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@

class SqlalchemyDsn(AnyUrl):
_constraints = UrlConstraints(
allowed_schemes=["sqlite+aiosqlite", "mysql+aiomysql"]
allowed_schemes=[
"sqlite+aiosqlite",
"mysql+aiomysql",
# The real scheme is with an underscore, (oracle+oracledb_async)
# but pydantic does not validate it, so we use this hack
"oracle+oracledb-async",
]
)


Expand Down
12 changes: 12 additions & 0 deletions diracx-db/src/diracx/db/sql/utils/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ def available_urls(cls) -> dict[str, str]:
db_url = os.environ[var_name]
if db_url == "sqlite+aiosqlite:///:memory:":
db_urls[db_name] = db_url
# pydantic does not allow for underscore in scheme
# so we do a special case
elif "_" in db_url.split(":")[0]:
# Validate the URL with a fake schema, and then store
# the original one
scheme_id = db_url.find(":")
fake_url = (
db_url[:scheme_id].replace("_", "-") + db_url[scheme_id:]
)
TypeAdapter(SqlalchemyDsn).validate_python(fake_url)
db_urls[db_name] = db_url

else:
db_urls[db_name] = str(
TypeAdapter(SqlalchemyDsn).validate_python(db_url)
Expand Down

0 comments on commit 3ddb10f

Please sign in to comment.