37 lines
1.1 KiB
Markdown
37 lines
1.1 KiB
Markdown
# Fix: Domain Column Shows Staff Names (Data Shift Bug)
|
|
|
|
## Root Cause
|
|
|
|
The bug is in `apps/complaints/utils.py` line 2144:
|
|
|
|
```python
|
|
row_data[48] = c.metadata.get("original_complaint_id", "") if c.metadata else "" # ID
|
|
```
|
|
|
|
When `c.metadata` exists but `original_complaint_id` is `None` (not missing from the dict), `dict.get()` returns `None` instead of the default `""`. This `None` value is written to the Excel cell, causing all subsequent columns to shift right by 1.
|
|
|
|
## Evidence
|
|
|
|
Test export shows:
|
|
- Col 48 (ID): `None` ← should be `""`
|
|
- Col 49 (Staff): `None` ← should be `"DR.ABDULHAMEED..."`
|
|
- Col 50 (Domain): `"DR.ABDULHAMEED..."` ← should be `"سريري"`
|
|
- Col 51 (Category): `"سريري"` ← should be `"الجودة"`
|
|
|
|
## Fix
|
|
|
|
Change line 2144 from:
|
|
```python
|
|
row_data[48] = c.metadata.get("original_complaint_id", "") if c.metadata else "" # ID
|
|
```
|
|
|
|
To:
|
|
```python
|
|
row_data[48] = c.metadata.get("original_complaint_id") or "" if c.metadata else "" # ID
|
|
```
|
|
|
|
Using `or ""` ensures that even if the key exists with a `None` value, it falls back to an empty string.
|
|
|
|
## File
|
|
`apps/complaints/utils.py` line 2144
|