Skip to content

Conversation

Copy link

Copilot AI commented Aug 19, 2025

The Touchpoints API was returning non-sequential question positions when questions had been deleted from forms. For example, a form with 6 questions would return positions like [1, 3, 5, 6, 7, 16] instead of the expected sequential values [1, 2, 3, 4, 5, 6].

This occurred because:

  1. When questions are deleted from forms, the remaining questions retain their original position values
  2. The API was using the raw questions association which preserves these database position values with gaps
  3. Frontend applications expect sequential positioning for proper display and functionality

Solution:

  • Created a new QuestionSerializer that normalizes position values to be sequential starting from 1
  • Updated both FormSerializer and FullFormSerializer to use the new serializer
  • Modified serializers to use the existing ordered_questions method which returns questions in the correct order across form sections
  • Added comprehensive test coverage to verify positions are always sequential

Example of the fix:

# Before: Raw database positions with gaps
[1, 3, 5, 6, 7, 16]

# After: Normalized sequential positions  
[1, 2, 3, 4, 5, 6]

The change is backward compatible and only affects the API response format - the underlying database positions remain unchanged to preserve form structure integrity.

Fixes #1876.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copy link
Author

Copilot AI commented Aug 19, 2025

@rileyseaburg 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Copilot AI changed the title [WIP] Touchpoints API Question Positions are incorrect Fix question position gaps in Touchpoints API responses Aug 19, 2025
Copilot AI requested a review from rileyseaburg August 19, 2025 19:23
Copilot finished work on behalf of rileyseaburg August 19, 2025 19:23
@MrNagoo
Copy link
Contributor

MrNagoo commented Aug 20, 2025

copilot has entered the chat

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.

Touchpoints API Question Positions are incorrect

3 participants