View Issue Details

This issue affects 1 person(s).
 2
IDProjectCategoryView StatusLast Update
20897Bug reportsImport/Exportpublic2026-11-25 17:21
Reporterjannik3445 Assigned Top_teichmann  
PrioritynoneSeverityminor 
Status ready for code reviewResolutionopen 
Product Version7.12.x 
Summary20897: Survey, group and question export lose and duplicate question attributes on PostgreSQL (no ORDER BY in chunked query)
Description

On PostgreSQL, the LSS export of a survey with more than 1,000 question attribute rows is wrong. Some attribute rows are in the export twice, and the same number of other rows are missing, so the total row count looks correct. The export imports without any error, but the imported survey has lost the missing attributes (for example cssclass, hidden, validation settings). Which rows are lost changes from one export to the next.

In our installation, 6 large surveys (about 2,000 to 5,000 attribute rows each) lost between 500 and 1,200 attribute rows each in every LSS export. The LSG and LSQ exports use the same query and have the same problem.

This is the same kind of bug as 20397. The fix for 20397 (commit 352fa9060f964a4bd78c92b6768e3c99f801fc12) added an ORDER BY to the answer and l10n queries, but not to the question attribute queries.

Cause

buildXMLFromQuery() reads the result in chunks of 1,000 rows with LIMIT/OFFSET:
https://github.com/LimeSurvey/LimeSurvey/blob/eb326311a4c1c386b24384b77226560db2a3c5fc/application/helpers/export_helper.php#L777-L779
https://github.com/LimeSurvey/LimeSurvey/blob/eb326311a4c1c386b24384b77226560db2a3c5fc/application/helpers/export_helper.php#L813-L818

The question attribute queries use GROUP BY but no ORDER BY:

Without ORDER BY, PostgreSQL does not keep the same row order between the chunk queries. With GROUP BY it often uses a hash aggregate, so the order changes and the chunks overlap and leave gaps. MariaDB and MySQL up to 5.7 sort GROUP BY results, so the bug usually does not show there. MySQL 8 no longer guarantees this order either.

The two SELECT DISTINCT conditions queries have no ORDER BY either:
https://github.com/LimeSurvey/LimeSurvey/blob/eb326311a4c1c386b24384b77226560db2a3c5fc/application/helpers/export_helper.php#L914-L920

Suggested fix

Add a fixed and unique order to these queries, as the 20397 fix did (https://github.com/LimeSurvey/LimeSurvey/blob/eb326311a4c1c386b24384b77226560db2a3c5fc/application/helpers/export_helper.php#L889-L905):

  • question attributes: ORDER BY qa.qid, qa.attribute, qa.language, qa.value (on MSSQL with cast(qa.value as varchar(4000)), because value is a text column)
  • conditions: ORDER BY cid

We run this patch on our LimeSurvey 7.12.1 installation. After it, all exports have every attribute row exactly once. I can open a pull request with this fix.

Steps To Reproduce

Steps to reproduce

  1. Use LimeSurvey 7.12.1 with PostgreSQL.
  2. Use a survey with more than 1,000 rows in question_attributes (for example a survey with many array questions in two languages).
  3. Export the survey as LSS (admin UI or RemoteControl export_survey).
  4. In the exported file, count the (qid, attribute, language) keys in <question_attributes> and compare them with the rows in the database:
    SELECT count(*) FROM question_attributes qa JOIN questions q ON q.qid = qa.qid WHERE q.sid = <sid>;

Expected result

Every attribute row is in the export exactly once.

Actual result

Some keys are in the export twice, and the same number of rows are missing. Importing the file gives a survey without these attributes.

TagsNo tags attached.
Bug heat2
Complete LimeSurvey version number (& build)7.12.1+261125 (also checked against master eb32631)
I will donate to the project if issue is resolvedNo
Browsernot relevant (server-side export)
Database type & versionPostgreSQL 18.7
Server OS (if known)Debian 12 (Docker)
Webserver software & version (if known)nginx 1.22.1 with PHP-FPM
PHP Version8.4.28
Git branch / Pull Request URL

Users monitoring this issue

There are no users monitoring this issue.

Activities

jannik3445

jannik3445

2026-11-25 16:28

reporter   ~87960

Pull request with the fix: https://github.com/LimeSurvey/LimeSurvey/pull/5602

Issue History

Date Modified Username Field Change
2026-11-25 16:23 jannik3445 New Issue
2026-11-25 16:28 jannik3445 Note Added: 87960
2026-11-25 16:28 jannik3445 Bug heat 0 => 2
2026-11-25 17:21 tibor.pacalat Assigned To => p_teichmann
2026-11-25 17:21 tibor.pacalat Status new => ready for code review