Fix CSV re-import dedup to use raw symbol for stable keys#763
Fix CSV re-import dedup to use raw symbol for stable keys#763
Conversation
…dempotency keys The review step (check_activities_import) computed idempotency keys using raw CSV symbol text (e.g. 'AAPL'), while the import step used the resolved asset UUID. Since the DB stored UUID-based keys, the review step never found duplicates on re-import, and the import step could also mismatch if asset resolution varied between imports. Fix: - Extract symbol_based_asset_id() helper that builds 'SYMBOL' or 'SYMBOL@MIC' consistently for both paths - Import step now uses get_symbol_code()/get_exchange_mic() instead of get_symbol_id() for key computation - create_activities inserts row-by-row and gracefully skips unique constraint violations as a safety net Closes #754
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8a9b6ce85c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let asset_id_for_key = Self::symbol_based_asset_id( | ||
| activity.get_symbol_code(), | ||
| activity.get_exchange_mic(), | ||
| ); |
There was a problem hiding this comment.
Match legacy idempotency keys during CSV dedupe
This change computes import keys from symbol@MIC only, but previously imported activities in existing databases were keyed with the old UUID-based asset_id path. On the first re-import after this upgrade, check_existing_duplicates and the unique index compare against the new hash and will miss those legacy rows, allowing the same historical activity to be inserted again instead of being flagged/skipped. Keep backward compatibility by checking both key formats (or backfilling old rows) before switching to symbol-only keys.
Useful? React with 👍 / 👎.
Problem
CSV re-imports were using resolved asset UUIDs for idempotency key computation, causing keys to differ between the review step and import step, breaking deduplication.
Solution
symbol_based_asset_id()helper that uses raw symbol + exchange MIC instead of UUIDbuild_import_idempotency_key()to use the new helper for consistent key generationUniqueViolationconstraints with debug loggingChanges
symbol_based_asset_id()helper and refactor key building logic