Add detailed skip tracking for phone imports

- Track skipped_no_phone and skipped_no_id separately
- Display skip information in admin UI with warning icon
- Clarify that empty phone numbers cannot be imported (PK constraint)
- Update documentation to explain expected skip behavior
- Example: 143 rows without phone numbers is correct, not an error

When importing PHONE.csv with empty phone numbers:
- Rows are properly skipped (cannot have NULL in primary key)
- User sees: '⚠️ Skipped: 143 rows without phone number'
- This is expected behavior, not a bug
This commit is contained in:
HotSwapp
2025-10-13 08:46:53 -05:00
parent 63809d46fb
commit ac98bded69
6 changed files with 26474 additions and 4 deletions

View File

@@ -773,7 +773,7 @@ def import_rolodex(db: Session, file_path: str) -> Dict[str, Any]:
def import_phone(db: Session, file_path: str) -> Dict[str, Any]:
"""Import PHONE.csv → LegacyPhone model with upsert logic."""
result = {'success': 0, 'errors': [], 'total_rows': 0, 'updated': 0, 'inserted': 0, 'skipped': 0}
result = {'success': 0, 'errors': [], 'total_rows': 0, 'updated': 0, 'inserted': 0, 'skipped': 0, 'skipped_no_phone': 0, 'skipped_no_id': 0}
try:
f, encoding = open_text_with_fallbacks(file_path)
@@ -789,7 +789,12 @@ def import_phone(db: Session, file_path: str) -> Dict[str, Any]:
rolodex_id = clean_string(row.get('Id'))
phone = clean_string(row.get('Phone'))
if not rolodex_id or not phone:
# Skip rows with missing required fields (phone is part of PK, cannot be NULL)
if not rolodex_id:
result['skipped_no_id'] += 1
continue
if not phone:
result['skipped_no_phone'] += 1
continue
# Create a composite key for tracking

View File

@@ -1133,7 +1133,7 @@ def run_auto_import_for_upload(db: Session, uploaded_items: List[Dict[str, Any]]
import_log.completed_at = datetime.now()
db.commit()
files_summary.append({
summary_item = {
"filename": item.get("filename"),
"stored_filename": stored_filename,
"import_type": import_type,
@@ -1142,7 +1142,18 @@ def run_auto_import_for_upload(db: Session, uploaded_items: List[Dict[str, Any]]
"success_count": result.get("success", 0),
"error_count": len(result.get("errors", [])),
"errors": (result.get("errors", [])[:10] if result.get("errors") else []),
})
}
# Add skip details if present (for phone imports and others that track this)
if result.get("skipped_no_phone", 0) > 0 or result.get("skipped_no_id", 0) > 0:
skip_details = []
if result.get("skipped_no_phone", 0) > 0:
skip_details.append(f"{result['skipped_no_phone']} rows without phone number")
if result.get("skipped_no_id", 0) > 0:
skip_details.append(f"{result['skipped_no_id']} rows without ID")
summary_item["skip_info"] = ", ".join(skip_details)
files_summary.append(summary_item)
if result.get("errors"):
stopped = True

View File

@@ -179,6 +179,8 @@
{% endfor %}
</ul>
</details>
{% elif item.skip_info %}
<small class="text-warning">⚠️ Skipped: {{ item.skip_info }}</small>
{% else %}
<span class="text-muted">None</span>
{% endif %}