Skip to content

Fix null gender crash when importing replacement forms#551

Merged
JohnMwashuma merged 4 commits intomainfrom
fix/handle-null-gender-replacement-forms
Feb 6, 2026
Merged

Fix null gender crash when importing replacement forms#551
JohnMwashuma merged 4 commits intomainfrom
fix/handle-null-gender-replacement-forms

Conversation

@JohnMwashuma
Copy link
Copy Markdown
Collaborator

Summary

  • Fix AttributeError: 'NoneType' object has no attribute 'upper' when importing result forms CSV that contains replacement form rows (empty center_code, station_number, gender)
  • Fix find_missing_center_codes SQL query to exclude NULL/empty center codes, which are expected for replacement forms

Changes

  • import_result_forms.py:158 - Add null guard before calling .upper() on gender field value
  • utils.py:301-306 - Add IS NOT NULL and != '' filters to find_missing_center_codes query so replacement form rows are not flagged as missing centers

Test plan

  • Added test fixture CSV with replacement form rows (empty center_code, station_number, gender, name)
  • Added test_async_import_result_forms_with_replacements verifying:
    • Import succeeds without error
    • 2 replacement forms created with is_replacement=True
    • Replacement forms have center=None, gender=None, station_number=None
  • All 765 existing tests pass with no regressions

Closes #550

Also fix find_missing_center_codes to exclude rows with NULL/empty
center_code values, which are expected for replacement forms.

Closes #550
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Feb 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.19%. Comparing base (a20ac93) to head (effc720).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #551   +/-   ##
=======================================
  Coverage   84.18%   84.19%           
=======================================
  Files         165      165           
  Lines       11452    11452           
=======================================
+ Hits         9641     9642    +1     
+ Misses       1811     1810    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

faith-mutua
faith-mutua previously approved these changes Feb 6, 2026
@JohnMwashuma JohnMwashuma merged commit 902e9b0 into main Feb 6, 2026
3 checks passed
@JohnMwashuma JohnMwashuma deleted the fix/handle-null-gender-replacement-forms branch February 6, 2026 12:44
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.

Fix null gender crash when importing replacement forms

3 participants