From 76ec2c0fa2252e634194fd3ef4a4158a1f6bc8d0 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Mon, 25 Jul 2022 10:54:58 -0400 Subject: [PATCH] fix: Pass key_fn to TableUpdate Operate ext Bugs (fixed): * PNL window crashes immediately when opened Cause: The 'Operate' ext fn aggregates an IObservable of TableUpdates w/ another IObservable of any T. If the latter fires before the former, an 'empty' TableUpdate is passed to the aggregate fn. When this happens, a null ref ex is thrown in the 'empty' TableUpdate's ctr because the key param is null. --- src/client/spark/Modules/Trading/PNL/VM/PNLVM.cs | 5 +++-- src/client/spark_api/api/Update/UpdateExtensions.cs | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/client/spark/Modules/Trading/PNL/VM/PNLVM.cs b/src/client/spark/Modules/Trading/PNL/VM/PNLVM.cs index a23bff661..d3330b0ce 100644 --- a/src/client/spark/Modules/Trading/PNL/VM/PNLVM.cs +++ b/src/client/spark/Modules/Trading/PNL/VM/PNLVM.cs @@ -128,8 +128,9 @@ _dispose = Disposable.Create( position_model.security_account_pnl.Operate( _calculation_type.observe_current(true), - (data, calc) => data.with(calc_type: calc) - ).FilterWithRaw(filter_src, PNLRowData.key_fn, null) + (data, calc) => data.with(calc_type: calc), + PNLRowData.key_fn) + .FilterWithRaw(filter_src, PNLRowData.key_fn, null) .OnDispatcher() .Subscribe(_update), _symbols_source(position_model.security_account_pnl).OnDispatcher().Subscribe(symbol_filter_items_observer), diff --git a/src/client/spark_api/api/Update/UpdateExtensions.cs b/src/client/spark_api/api/Update/UpdateExtensions.cs index adda29019..04a9938ff 100644 --- a/src/client/spark_api/api/Update/UpdateExtensions.cs +++ b/src/client/spark_api/api/Update/UpdateExtensions.cs @@ -500,6 +500,7 @@ namespace bts.api.core { this IObservable> source, IObservable param_source, Func operate, + Func key_fn, TParam init_param = default ) where TKey : IEquatable { return AggregateLatest( @@ -507,8 +508,8 @@ namespace bts.api.core { param_source, on_left, on_right, - () => TableUpdate.empty, - TableUpdate.empty, + () => TableUpdate.mk_empty(key_fn), + TableUpdate.mk_empty(key_fn), init_param); TableUpdate on_left(