Fix template variable interpolation by creating params copy
Root cause: params = reasoning_data.get('parameters', {}) created a reference
to the dictionary instead of a copy. When modifying params to add
product_names_joined, the change didn't persist because the database object
was immutable/read-only.
Changes:
- dashboard_service.py:408 - Create dict copy for PO params
- dashboard_service.py:632 - Create dict copy for batch params
- Added clean_old_dashboard_data.py utility script to remove old POs/batches
with malformed reasoning_data
The fix ensures template variables like {{supplier_name}}, {{product_names_joined}},
{{days_until_stockout}}, etc. are properly interpolated in the dashboard.
This commit is contained in:
@@ -404,8 +404,8 @@ class DashboardService:
|
||||
reasoning_type = reasoning_data.get('type', 'inventory_replenishment')
|
||||
reasoning_type_i18n_key = self._get_reasoning_type_i18n_key(reasoning_type, context="purchaseOrder")
|
||||
|
||||
# Preprocess parameters for i18n
|
||||
params = reasoning_data.get('parameters', {})
|
||||
# Preprocess parameters for i18n - MUST create a copy to avoid modifying immutable database objects
|
||||
params = dict(reasoning_data.get('parameters', {}))
|
||||
# Convert product_names array to product_names_joined string
|
||||
if 'product_names' in params and isinstance(params['product_names'], list):
|
||||
params['product_names_joined'] = ', '.join(params['product_names'])
|
||||
@@ -629,7 +629,7 @@ class DashboardService:
|
||||
"reasoning_data": reasoning_data, # Structured data for i18n
|
||||
"reasoning_i18n": {
|
||||
"key": reasoning_type_i18n_key,
|
||||
"params": reasoning_data.get('parameters', {})
|
||||
"params": dict(reasoning_data.get('parameters', {})) # Create a copy to avoid immutable object issues
|
||||
},
|
||||
"status_i18n": status_i18n # i18n for status text
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user