Skip to content

Fix: Handle trigger format backward compatibility for pyxform 4.1.0#2993

Merged
ukanga merged 4 commits intomainfrom
fix/issue-2992-trigger-format-backward-compatibility
Jan 14, 2026
Merged

Fix: Handle trigger format backward compatibility for pyxform 4.1.0#2993
ukanga merged 4 commits intomainfrom
fix/issue-2992-trigger-format-backward-compatibility

Conversation

@ukanga
Copy link
Member

@ukanga ukanga commented Jan 13, 2026

Changes / Features implemented

Extended _get_survey() in onadata/apps/logger/models/xform.py to handle backward compatibility for XForms published before PR #2961. Old forms store trigger data as strings (e.g., "${assessor}") but pyxform 4.1.0 expects tuples (e.g., ("assessor",)).

The fix:

  • Catches trigger-related PyXFormError exceptions in _get_survey()
  • Falls back to regenerating the survey from the XLS file using get_survey_and_json_from_xlsform()
  • Persists the regenerated workbook_json to the database to avoid repeated XLS parsing on subsequent requests

Steps taken to verify this change does what is intended

  • Added unit test test_get_survey_fallback_on_trigger_error that:
    • Publishes a form and stores the original workbook_json
    • Simulates old format by setting xform.json to survey.to_json_dict()
    • Mocks SurveyElementBuilder to raise trigger error on first call
    • Verifies the fallback regenerates from XLS and restores workbook_json
  • Ran full xform test suite (19 tests) - all pass

Side effects of implementing this change

  • Forms with trigger errors will have their JSON automatically updated to the correct workbook_json format on first access
  • This uses the existing get_survey_and_json_from_xlsform() pattern already used elsewhere in the codebase

Before submitting this PR for review, please make sure you have:

  • Included tests
  • Updated documentation

Closes #2992

Old XForms published before PR #2961 store trigger data as strings
(e.g., "${assessor}") in their JSON field. PyXForm 4.1.0 expects
triggers as tuples, causing PyXFormError when processing submissions.

This fix extends _get_survey() to:
- Catch trigger-related PyXFormErrors
- Fall back to regenerating from XLS file
- Persist the workbook_json to avoid repeated XLS parsing

Fixes #2992
Branch names containing `/` (e.g., `fix/issue-2992`) cause Docker build
failures because `/` is invalid in Docker image tags.

Changes:
- Add docker/metadata-action@v5 to sanitize tags automatically
- Update docker/build-push-action to v6 (latest)
- Update other actions to latest versions in docker-image-build.yml
- Remove redundant manual branch/version extraction steps

Fixes the Trivy security check failure on branches with `/` in the name.
CodeQL Action v3 will be deprecated in December 2026. v4 runs on
Node.js 24 runtime.

Ref: https://github.blog/changelog/2025-10-28-upcoming-deprecation-of-codeql-action-v3/
@ukanga ukanga merged commit 715ea1b into main Jan 14, 2026
11 checks passed
@ukanga ukanga deleted the fix/issue-2992-trigger-format-backward-compatibility branch January 14, 2026 07:00
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.

PyXFormError: Internal error: PyXForm expected processed trigger data as a tuple, but received a type '<class 'str'>' with value '${assessor}'.

2 participants