Skip to content

Commit 059fed9

Browse files
committed
Merge branch 'release/2.025.10' into release/2.025.14
2 parents 937957a + c68e802 commit 059fed9

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

kobo/apps/subsequences/tests/test_proj_advanced_features.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from django.test import TestCase
33
from django.utils import timezone
44
from model_bakery import baker
5+
from rest_framework import status
56

67
from kpi.models import Asset
78

@@ -89,3 +90,30 @@ def test_details_for_translation_export(self):
8990
addl_fields = _afj['additional_fields']
9091
assert len(addl_fields) == 2
9192
assert len(engines) == 1
93+
94+
def test_qpath_to_xpath_with_renamed_question(self):
95+
"""
96+
Test that the analysis form JSON can handle a question that has been
97+
renamed or deleted from the survey, but is still referenced in advanced
98+
features or known columns.
99+
100+
This ensures that the asset endpoint does not return a 500 error when
101+
processing legacy qpaths that no longer exist in the survey definition.
102+
"""
103+
asset = self.sample_asset(advanced_features={
104+
'translation': {
105+
'values': ['q1'],
106+
'languages': ['en', 'fr']
107+
},
108+
})
109+
110+
# Simulate known_cols with a legacy (renamed or deleted) question
111+
asset.known_cols = [
112+
'group_ia0id17-q1:translation:en',
113+
'group_ia0id17-q1:translation:fr'
114+
]
115+
asset.save()
116+
117+
self.client.force_login(asset.owner)
118+
resp = self.client.get(f'/api/v2/assets/{asset.uid}/')
119+
assert resp.status_code == status.HTTP_200_OK

kobo/apps/subsequences/utils/deprecation.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ def qpath_to_xpath(qpath: str, asset: 'Asset') -> str:
7979
if '$qpath' in row and '$xpath' in row and row['$qpath'] == qpath:
8080
return row['$xpath']
8181

82+
# If the `qpath` refers to a question that was renamed or deleted, it may
83+
# no longer match any XPath in the form. In such cases, where it's still
84+
# present in known_cols, skip this field by returning an empty string
85+
dashed_qpath = qpath.replace('/', '-')
86+
for known_col in asset.known_cols:
87+
if known_col.startswith(dashed_qpath):
88+
return ''
89+
8290
# Could not find it from the survey, let's try to detect it automatically
8391
xpaths = asset.get_attachment_xpaths(deployed=True)
8492
for xpath in xpaths:

0 commit comments

Comments
 (0)