Skip to content

Commit bd9e262

Browse files
authored
Better Validation (#495)
No need to require a host or username in database URL, both are optional in the standard. Also remove code that emits warnings if a function not marked as a coroutine is called from an event loop, as it emits false positives when using non-asyncio event loops.
1 parent 4eed711 commit bd9e262

File tree

3 files changed

+0
-41
lines changed

3 files changed

+0
-41
lines changed

dbos/_core.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,6 @@
9393
DEBOUNCER_WORKFLOW_NAME = "_dbos_debouncer_workflow"
9494

9595

96-
def check_is_in_coroutine() -> bool:
97-
try:
98-
asyncio.get_running_loop()
99-
return True
100-
except RuntimeError:
101-
return False
102-
103-
10496
class WorkflowHandleFuture(Generic[R]):
10597

10698
def __init__(self, workflow_id: str, future: Future[R], dbos: "DBOS"):
@@ -856,11 +848,6 @@ def record_get_result(func: Callable[[], R]) -> R:
856848
dbos._sys_db.record_get_result(workflow_id, serialized_r, None)
857849
return r
858850

859-
if check_is_in_coroutine() and not inspect.iscoroutinefunction(func):
860-
dbos_logger.warning(
861-
f"Sync workflow ({get_dbos_func_name(func)}) shouldn't be invoked from within another async function. Define it as async or use asyncio.to_thread instead."
862-
)
863-
864851
outcome = (
865852
wfOutcome.wrap(init_wf, dbos=dbos)
866853
.also(DBOSAssumeRole(rr))
@@ -1046,10 +1033,6 @@ def wrapper(*args: Any, **kwargs: Any) -> Any:
10461033
assert (
10471034
ctx.is_workflow()
10481035
), "Transactions must be called from within workflows"
1049-
if check_is_in_coroutine():
1050-
dbos_logger.warning(
1051-
f"Transaction function ({get_dbos_func_name(func)}) shouldn't be invoked from within another async function. Use asyncio.to_thread instead."
1052-
)
10531036
with DBOSAssumeRole(rr):
10541037
return invoke_tx(*args, **kwargs)
10551038
else:
@@ -1194,10 +1177,6 @@ def check_existing_result() -> Union[NoResult, R]:
11941177

11951178
@wraps(func)
11961179
def wrapper(*args: Any, **kwargs: Any) -> Any:
1197-
if check_is_in_coroutine() and not inspect.iscoroutinefunction(func):
1198-
dbos_logger.warning(
1199-
f"Sync step ({get_dbos_func_name(func)}) shouldn't be invoked from within another async function. Define it as async or use asyncio.to_thread instead."
1200-
)
12011180
# If the step is called from a workflow, run it as a step.
12021181
# Otherwise, run it as a normal function.
12031182
ctx = get_local_dbos_context()

dbos/_dbos_config.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,6 @@ def is_valid_database_url(database_url: str) -> bool:
478478
return True
479479
url = make_url(database_url)
480480
required_fields = [
481-
("username", "Username must be specified in the connection URL"),
482-
("host", "Host must be specified in the connection URL"),
483481
("database", "Database name must be specified in the connection URL"),
484482
]
485483
for field_name, error_message in required_fields:

tests/test_config.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -610,24 +610,6 @@ def test_configure_db_engine_parameters_empty_user_kwargs():
610610

611611

612612
def test_process_config_with_wrong_db_url():
613-
# Missing username
614-
config: ConfigFile = {
615-
"name": "some-app",
616-
"database_url": "postgres://:password@h:1234/dbname",
617-
}
618-
with pytest.raises(DBOSInitializationError) as exc_info:
619-
process_config(data=config)
620-
assert "Username must be specified in the connection URL" in str(exc_info.value)
621-
622-
# Missing host
623-
config: ConfigFile = {
624-
"name": "some-app",
625-
"database_url": "postgres://user:password@:1234/dbname",
626-
}
627-
with pytest.raises(DBOSInitializationError) as exc_info:
628-
process_config(data=config)
629-
assert "Host must be specified in the connection URL" in str(exc_info.value)
630-
631613
# Missing dbname
632614
config: ConfigFile = {
633615
"name": "some-app",

0 commit comments

Comments
 (0)