|
43 | 43 | from .conftest import IsDatetime, IsStr
|
44 | 44 |
|
45 | 45 | try:
|
| 46 | + import importlib.metadata |
| 47 | + |
46 | 48 | from dbos import DBOS, DBOSConfig, SetWorkflowID
|
| 49 | + from packaging.version import Version |
47 | 50 |
|
48 | 51 | from pydantic_ai.durable_exec.dbos import DBOSAgent, DBOSMCPServer, DBOSModel
|
| 52 | + |
| 53 | + dbos_version = Version(importlib.metadata.version('dbos')) |
49 | 54 | except ImportError: # pragma: lax no cover
|
50 | 55 | pytest.skip('DBOS is not installed', allow_module_level=True)
|
51 | 56 |
|
@@ -110,9 +115,10 @@ def workflow_raises(exc_type: type[Exception], exc_message: str) -> Iterator[Non
|
110 | 115 | DBOS_SQLITE_FILE = 'dbostest.sqlite'
|
111 | 116 | DBOS_CONFIG: DBOSConfig = {
|
112 | 117 | 'name': 'pydantic_dbos_tests',
|
113 |
| - 'database_url': f'sqlite:///{DBOS_SQLITE_FILE}', |
114 | 118 | 'system_database_url': f'sqlite:///{DBOS_SQLITE_FILE}',
|
115 | 119 | 'run_admin_server': False,
|
| 120 | + # enable_otlp requires dbos>1.14 |
| 121 | + 'enable_otlp': True, |
116 | 122 | }
|
117 | 123 |
|
118 | 124 |
|
@@ -1042,9 +1048,19 @@ async def simple_event_stream_handler(
|
1042 | 1048 | ):
|
1043 | 1049 | pass
|
1044 | 1050 |
|
1045 |
| - with workflow_raises(TypeError, snapshot('Serialized function should be defined at the top level of a module')): |
| 1051 | + with pytest.raises(Exception) as exc_info: |
1046 | 1052 | await simple_dbos_agent.run('What is the capital of Mexico?', event_stream_handler=simple_event_stream_handler)
|
1047 | 1053 |
|
| 1054 | + if dbos_version <= Version('1.14'): # pragma: lax no cover |
| 1055 | + # Older DBOS versions used jsonpickle |
| 1056 | + assert str(exc_info.value) == snapshot('Serialized function should be defined at the top level of a module') |
| 1057 | + else: |
| 1058 | + # Newer DBOS versions use pickle |
| 1059 | + assert ( |
| 1060 | + "local object 'test_dbos_agent_run_in_workflow_with_event_stream_handler.<locals>.simple_event_stream_handler'" |
| 1061 | + in str(exc_info.value) |
| 1062 | + ) |
| 1063 | + |
1048 | 1064 |
|
1049 | 1065 | async def test_dbos_agent_run_in_workflow_with_model(allow_model_requests: None, dbos: DBOS):
|
1050 | 1066 | # A non-DBOS model is not wrapped as steps so it's not deterministic and cannot be used in a DBOS workflow.
|
@@ -1142,15 +1158,19 @@ async def get_model_name(ctx: RunContext[UnserializableDeps]) -> int:
|
1142 | 1158 | async def test_dbos_agent_with_unserializable_deps_type(allow_model_requests: None, dbos: DBOS):
|
1143 | 1159 | unserializable_deps_dbos_agent = DBOSAgent(unserializable_deps_agent)
|
1144 | 1160 | # Test this raises a serialization error because httpx.AsyncClient is not serializable.
|
1145 |
| - with pytest.raises( |
1146 |
| - Exception, |
1147 |
| - match='object proxy must define __reduce_ex__()', |
1148 |
| - ): |
| 1161 | + with pytest.raises(Exception) as exc_info: |
1149 | 1162 | async with AsyncClient() as client:
|
1150 | 1163 | # This will trigger the client to be unserializable
|
1151 | 1164 | logfire.instrument_httpx(client, capture_all=True)
|
1152 | 1165 | await unserializable_deps_dbos_agent.run('What is the model name?', deps=UnserializableDeps(client=client))
|
1153 | 1166 |
|
| 1167 | + if dbos_version <= Version('1.14'): # pragma: lax no cover |
| 1168 | + # Older DBOS versions used jsonpickle |
| 1169 | + assert str(exc_info.value) == snapshot('object proxy must define __reduce_ex__()') |
| 1170 | + else: |
| 1171 | + # Newer DBOS versions use pickle |
| 1172 | + assert str(exc_info.value) == snapshot("cannot pickle '_thread.RLock' object") |
| 1173 | + |
1154 | 1174 |
|
1155 | 1175 | # Test dynamic toolsets in an agent with DBOS
|
1156 | 1176 |
|
|
0 commit comments