v2.0.0rc182
Pre-release
Pre-release
·
183 commits
to lex-app-v2
since this release
Fix broken realtime logs and premature audit status on 202 calculations
After the threadpool refactor (4b819c5), two issues emerged for
background calculations triggered via HTTP 202:
1. Realtime WebSocket logs and `calculation_record` field stopped
working because `copy_context()` only copies ContextVar bindings
(references), not the underlying mutable objects. When the request
thread exits `model_logging_context` and pops the instance from the
shared ModelContext stack, the background thread's copied reference
sees the same empty stack — ContextResolver.resolve() can no longer
determine `current_record`, breaking WebSocket routing and DB
persistence of CalculationLog entries.
Fix: Set a fresh `ModelContext([instance])` at the start of
`_invoke_calculate_hook` inside `ctx.run()`, giving the background
thread its own independent model context.
2. AuditLogStatus was unconditionally marked 'success' in
`perform_update` right after `serializer.save()`, even though the
actual calculation hadn't started yet (only the field data was
persisted). This gave operators a false impression that the
operation completed successfully.
Fix: Skip the immediate 'success' update when
`instance._defer_calculate_hook` is set. The existing
`ensure_terminal_calculation_audit` (called from
`execute_calculation_sync` / `_finalize_pending_terminal_audit`)
already handles setting the correct terminal status ('success' or
'failure') once the calculation actually finishes.