Skip to content

Commit 6121e13

Browse files
Fixing indent issue with kwargs["extra"] (#789)
* Fixing indent issue with kwargs["extra"] * indent other two lines * Extend logging tests to cover no-info branch with bug --------- Co-authored-by: Dan Davison <dan.davison@temporal.io>
1 parent 615122d commit 6121e13

2 files changed

Lines changed: 56 additions & 25 deletions

File tree

temporalio/workflow/_sandbox.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,9 @@ def process(
268268
else None,
269269
)
270270

271-
kwargs["extra"] = {**extra, **(kwargs.get("extra") or {})}
272-
if msg_extra:
273-
msg = f"{msg} ({msg_extra})"
271+
kwargs["extra"] = {**extra, **(kwargs.get("extra") or {})}
272+
if msg_extra:
273+
msg = f"{msg} ({msg_extra})"
274274
return msg, kwargs
275275

276276
def log(

tests/worker/test_workflow.py

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,8 +2242,27 @@ def last_signal(self) -> str:
22422242
return self._last_signal
22432243

22442244

2245-
async def test_workflow_logging(client: Client):
2246-
workflow.logger.full_workflow_info_on_extra = True
2245+
@pytest.mark.parametrize(
2246+
"with_workflow_info",
2247+
[True, False],
2248+
)
2249+
async def test_workflow_logging(client: Client, with_workflow_info: bool):
2250+
orig_on_message = workflow.logger.workflow_info_on_message
2251+
orig_on_extra = workflow.logger.workflow_info_on_extra
2252+
orig_full_on_extra = workflow.logger.full_workflow_info_on_extra
2253+
2254+
try:
2255+
workflow.logger.workflow_info_on_message = with_workflow_info
2256+
workflow.logger.workflow_info_on_extra = with_workflow_info
2257+
workflow.logger.full_workflow_info_on_extra = with_workflow_info
2258+
await _do_workflow_logging_test(client, with_workflow_info)
2259+
finally:
2260+
workflow.logger.workflow_info_on_message = orig_on_message
2261+
workflow.logger.workflow_info_on_extra = orig_on_extra
2262+
workflow.logger.full_workflow_info_on_extra = orig_full_on_extra
2263+
2264+
2265+
async def _do_workflow_logging_test(client: Client, with_workflow_info: bool):
22472266
with LogCapturer().logs_captured(
22482267
workflow.logger.base_logger, activity.logger.base_logger
22492268
) as capturer:
@@ -2270,31 +2289,43 @@ async def test_workflow_logging(client: Client):
22702289
assert "signal 2" == await handle.query(LoggingWorkflow.last_signal)
22712290

22722291
# Confirm logs were produced
2273-
assert capturer.find_log("Signal: signal 1 ({'attempt':")
2292+
assert capturer.find_log("Signal: signal 1")
22742293
assert capturer.find_log("Signal: signal 2")
22752294
assert capturer.find_log("Update: update 1")
22762295
assert capturer.find_log("Update: update 2")
22772296
assert capturer.find_log("Query called")
22782297
assert not capturer.find_log("Signal: signal 3")
2279-
# Also make sure it has some workflow info and correct funcName
2280-
record = capturer.find_log("Signal: signal 1")
2281-
assert (
2282-
record
2283-
and record.__dict__["temporal_workflow"]["workflow_type"]
2284-
== "LoggingWorkflow"
2285-
and record.funcName == "my_signal"
2286-
)
2287-
# Since we enabled full info, make sure it's there
2288-
assert isinstance(record.__dict__["workflow_info"], workflow.Info)
2289-
# Check the log emitted by the update execution.
2290-
record = capturer.find_log("Update: update 1")
2291-
assert (
2292-
record
2293-
and record.__dict__["temporal_workflow"]["update_id"] == "update-1"
2294-
and record.__dict__["temporal_workflow"]["update_name"] == "my_update"
2295-
and "'update_id': 'update-1'" in record.message
2296-
and "'update_name': 'my_update'" in record.message
2297-
)
2298+
2299+
if with_workflow_info:
2300+
record = capturer.find_log("Signal: signal 1 ({'attempt':")
2301+
assert (
2302+
record
2303+
and record.__dict__["temporal_workflow"]["workflow_type"]
2304+
== "LoggingWorkflow"
2305+
and record.funcName == "my_signal"
2306+
)
2307+
# Since we enabled full info, make sure it's there
2308+
assert isinstance(record.__dict__["workflow_info"], workflow.Info)
2309+
2310+
# Check the log emitted by the update execution.
2311+
record = capturer.find_log("Update: update 1")
2312+
assert (
2313+
record
2314+
and record.__dict__["temporal_workflow"]["update_id"] == "update-1"
2315+
and record.__dict__["temporal_workflow"]["update_name"] == "my_update"
2316+
and "'update_id': 'update-1'" in record.message
2317+
and "'update_name': 'my_update'" in record.message
2318+
)
2319+
else:
2320+
record = capturer.find_log("Signal: signal 1")
2321+
assert record and "temporal_workflow" not in record.__dict__
2322+
assert record and "workflow_info" not in record.__dict__
2323+
2324+
record = capturer.find_log("Update: update 1")
2325+
assert record and "temporal_workflow" not in record.__dict__
2326+
assert record and "workflow_info" not in record.__dict__
2327+
assert "'update_id': 'update-1'" not in record.message
2328+
assert "'update_name': 'my_update'" not in record.message
22982329

22992330
# Clear queue and start a new one with more signals
23002331
capturer.log_queue.queue.clear()

0 commit comments

Comments
 (0)