Skip to content

Commit 42af0cc

Browse files
authored
Better Destroy (#193)
For `DBOS.destroy()` to destroy the global registry by default (essentially un-decorating all DBOS functions) is unintuitive and makes it harder to write tests for DBOS applications. This PR changes its behavior not not destroy the global registry by default.
1 parent 1b3cff2 commit 42af0cc

File tree

5 files changed

+25
-9
lines changed

5 files changed

+25
-9
lines changed

dbos/_dbos.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def __new__(
245245
return _dbos_global_instance
246246

247247
@classmethod
248-
def destroy(cls, *, destroy_registry: bool = True) -> None:
248+
def destroy(cls, *, destroy_registry: bool = False) -> None:
249249
global _dbos_global_instance
250250
if _dbos_global_instance is not None:
251251
_dbos_global_instance._destroy()

dbos/_sys_db.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ def set_workflow_status(
367367
with self.engine.begin() as c:
368368
stmt = (
369369
sa.update(SystemSchema.workflow_status)
370-
.where(SystemSchema.workflow_inputs.c.workflow_uuid == workflow_uuid)
370+
.where(SystemSchema.workflow_status.c.workflow_uuid == workflow_uuid)
371371
.values(
372372
status=status,
373373
)

tests/conftest.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def cleanup_test_databases(config: ConfigFile, postgres_db_engine: sa.Engine) ->
9898
def dbos(
9999
config: ConfigFile, cleanup_test_databases: None
100100
) -> Generator[DBOS, Any, None]:
101-
DBOS.destroy()
101+
DBOS.destroy(destroy_registry=True)
102102

103103
# This launches for test convenience.
104104
# Tests add to running DBOS and then call stuff without adding
@@ -109,14 +109,14 @@ def dbos(
109109
DBOS.launch()
110110

111111
yield dbos
112-
DBOS.destroy()
112+
DBOS.destroy(destroy_registry=True)
113113

114114

115115
@pytest.fixture()
116116
def dbos_fastapi(
117117
config: ConfigFile, cleanup_test_databases: None
118118
) -> Generator[Tuple[DBOS, FastAPI], Any, None]:
119-
DBOS.destroy()
119+
DBOS.destroy(destroy_registry=True)
120120
app = FastAPI()
121121
dbos = DBOS(fastapi=app, config=config)
122122

@@ -125,14 +125,14 @@ def dbos_fastapi(
125125
DBOS.launch()
126126

127127
yield dbos, app
128-
DBOS.destroy()
128+
DBOS.destroy(destroy_registry=True)
129129

130130

131131
@pytest.fixture()
132132
def dbos_flask(
133133
config: ConfigFile, cleanup_test_databases: None
134134
) -> Generator[Tuple[DBOS, Flask], Any, None]:
135-
DBOS.destroy()
135+
DBOS.destroy(destroy_registry=True)
136136
app = Flask(__name__)
137137

138138
dbos = DBOS(flask=app, config=config)
@@ -142,7 +142,7 @@ def dbos_flask(
142142
DBOS.launch()
143143

144144
yield dbos, app
145-
DBOS.destroy()
145+
DBOS.destroy(destroy_registry=True)
146146

147147

148148
# Pretty-print test names

tests/test_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ async def test_async_tx() -> None:
303303
pass
304304

305305
# destroy call needed to avoid "functions were registered but DBOS() was not called" warning
306-
DBOS.destroy()
306+
DBOS.destroy(destroy_registry=True)
307307

308308

309309
@pytest.mark.asyncio

tests/test_dbos.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,3 +1212,19 @@ def test_workflow_dest() -> str:
12121212

12131213
# Reset logging
12141214
logging.getLogger("dbos").propagate = original_propagate
1215+
1216+
1217+
def test_destroy_semantics(dbos: DBOS, config: ConfigFile) -> None:
1218+
1219+
@DBOS.workflow()
1220+
def test_workflow(var: str) -> str:
1221+
return var
1222+
1223+
var = "test"
1224+
assert test_workflow(var) == var
1225+
1226+
DBOS.destroy()
1227+
DBOS(config=config)
1228+
DBOS.launch()
1229+
1230+
assert test_workflow(var) == var

0 commit comments

Comments
 (0)