Skip to content

Fix Sentinel watchlist item uploads and request bodies - #962

Open
Behzad Motaghi (Motaghi) wants to merge 1 commit into
microsoft:mainfrom
Motaghi:fix/msticpy-watchlists
Open

Behzad Motaghi (Motaghi) wants to merge 1 commit into
microsoft:mainfrom
Motaghi:fix/msticpy-watchlists

Conversation

@Motaghi

Copy link
Copy Markdown

This fixes three problems in sentinel_watchlists.py that sit on the same upload path.

create_watchlist and add_watchlist_item send str() of a Python dict as the request body, so it uses single quotes and isn't valid JSON, although the request declares Content-Type: application/json. Both now pass the payload through HTTPX's json parameter.

add_watchlist_item turns Series and DataFrame input into row dictionaries, then puts the original item in every request, so a two-row DataFrame sent the whole frame's text in both PUTs. Each PUT now sends its own row.

With overwrite=True, the item ID lookup matched any row containing any of the new item's values. If an earlier row shared one value, for example the same Type, that row was overwritten with the new item, so its original values were lost and the watchlist ended up with two identical rows. The lookup now uses the same all-column comparison as the existence check.

Each fix has a respx test that fails on main and passes here: Both request bodies decode as JSON with quotes and newlines intact (including CSV content), dict, Series and DataFrame input send one row per PUT, and an overwrite with a partial match ahead of the exact row targets the exact row. All 12 watchlist tests, the focused pre-commit hooks and mypy pass. Full disclosure, I haven't run this against a live workspace.

numpy int64 and NaN values aren't JSON serializable so I left these alone, so rows like that now raise before the request instead of sending an unreadable body.

I used gpt-6.1-sol via Codex, run from T3 Code, to write the patch and tests, and Claude Opus 5.5 reviewed the change independently. I've read and verified the diff myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant