Skip to content

294718: Enhance Batch model and admin functionality#320

Open
arsen-vs wants to merge 9 commits intodevelopfrom
feature/294718-Kobo-import-refactor
Open

294718: Enhance Batch model and admin functionality#320
arsen-vs wants to merge 9 commits intodevelopfrom
feature/294718-Kobo-import-refactor

Conversation

@arsen-vs
Copy link
Contributor

@arsen-vs arsen-vs commented Jan 27, 2026

  • Introduced status and kobo_last_page fields to the Batch model to track the import status and pagination.
  • Updated BatchAdmin to display the new fields and filter by batch status.
  • Modified import processing functions to set batch status during data import and handle loading states.
  • Added migration to create new fields and set existing batches to complete.
  • Enhanced tests to validate new functionality and ensure correct behavior during batch processing.

These changes improve the tracking and management of batch imports, enhancing overall functionality and user experience.

AB#294718

@arsen-vs arsen-vs requested a review from saxix as a code owner January 27, 2026 20:57
@codecov
Copy link

codecov bot commented Jan 29, 2026

Codecov Report

❌ Patch coverage is 98.85057% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 96.48%. Comparing base (d99dc00) to head (5cd6378).

Files with missing lines Patch % Lines
src/country_workspace/contrib/kobo/sync.py 97.91% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #320      +/-   ##
===========================================
+ Coverage    96.46%   96.48%   +0.02%     
===========================================
  Files          217      217              
  Lines         8221     8269      +48     
  Branches       833      839       +6     
===========================================
+ Hits          7930     7978      +48     
  Misses         160      160              
  Partials       131      131              

☔ 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.

Copy link
Member

@saxix saxix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not clear where the transaction management happen. Can we add some comment to details the process, this can be useful for future updates.
Linked to the transaction management, I saw test_import_data_reschedules_when_incomplete and test_import_asset_timeboxed_returns_incomplete_and_keeps_watermark, to test recovery I would add a test the check for errors but we also check previous data are persisted to the disk

@domdinicola
Copy link
Collaborator

@arsen-vs pls resolve conflicts

Arsen P added 8 commits February 5, 2026 00:14
- Introduced `status` and `kobo_last_page` fields to the Batch model to track the import status and pagination.
- Updated BatchAdmin to display the new fields and filter by batch status.
- Modified import processing functions to set batch status during data import and handle loading states.
- Added migration to create new fields and set existing batches to complete.
- Enhanced tests to validate new functionality and ensure correct behavior during batch processing.

These changes improve the tracking and management of batch imports, enhancing overall functionality and user experience.
- Added a test for `import_asset` to validate timeboxed updates and ensure correct handling of submissions, including the update of `kobo_last_page` and logging of last successful submission ID.
- Introduced a new test for `import_data` to verify rescheduling behavior when the import is incomplete, ensuring proper job creation and validation of asset import calls.
- Updated existing tests to include assertions for new functionality and improved coverage of the import process.

These changes enhance the robustness of the Kobo sync functionality and ensure accurate tracking of import states.
- Removed `kobo_last_page` from `BatchAdmin` and `Batch` model to streamline the import process and focus on essential fields.
- Updated `import_asset` and related functions to eliminate unnecessary parameters and improve clarity in submission handling.
- Adjusted tests to reflect changes in the `submissions` method, ensuring accurate assertions without the `start_page` parameter.

These modifications enhance the maintainability of the code and improve the overall efficiency of the import process.
- Adjusted assertions in `test_create_individuals` to check for keys from the processed mock data.
- Removed references to `kobo_last_page` in `test_import_data` and `test_import_data_reschedules_when_incomplete` to align with recent refactoring of the Batch model.
- These changes ensure that tests accurately reflect the current state of the codebase and improve clarity in the import process.
- Added a status assertion for the `test_import_from_rdi` function to reflect the loading state during import.
- Updated the `test_household_filter_queryset_with_program` to include a filter for batch status, ensuring accurate filtering based on the new Batch model structure.

These changes enhance the accuracy of the tests by aligning them with the current Batch model's functionality and improving the validation of import processes.
…lity

- Introduced a new test class for `BatchAdmin.beneficiaries` to validate behavior when the batch status is LOADING, ensuring that households and individuals return empty querysets.
- Added a test for `import_data` to confirm that it resumes an existing batch when `job.batch_id` is set, preventing the creation of a new batch and ensuring correct handling of import processes.

These enhancements improve test coverage and ensure accurate validation of batch processing and import functionality.
…rtions

- Replaced `RequestFactory` with `Client` for testing the `beneficiaries` view, improving the simulation of user interactions.
- Updated assertions in `test_import_data_resumes_existing_batch` to ensure the call count for `select_for_update` is validated correctly.

These changes enhance the reliability of the tests and ensure they accurately reflect the intended functionality of the BatchAdmin and import processes.
- Updated `import_asset` to ensure each submission is processed in its own transaction, allowing for partial success and rollback of only failed submissions.
- Added detailed comments to clarify transaction handling and watermark persistence for recovery.
- Introduced a new test to verify that earlier submissions remain intact when a later submission fails, ensuring data integrity during import processes.

These changes improve the robustness of the import functionality and enhance error handling in the Kobo sync process.
@arsen-vs arsen-vs force-pushed the feature/294718-Kobo-import-refactor branch from f29a687 to 38bbd79 Compare February 4, 2026 22:14
- Updated the `test_base_import_form_includes_transformers_when_program_provided` to create transformers associated with a specific beneficiary group, enhancing the test setup.
- Revised the docstring in `test_base_import_form_pops_individual_mapping_when_no_individual_checker` for better clarity regarding the behavior of household fields in people-only programs.

These changes improve the readability and reliability of the tests related to import forms and transformers.
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.

3 participants