View Issue Details

This issue affects 1 person(s).
 8
IDProjectCategoryView StatusLast Update
20457Bug reportsSurvey participants (Tokens)public2026-09-17 14:29
Reporterriku Assigned Toc_schmitz  
PrioritynoneSeveritycrash 
Status closedResolutionfixed 
Product Version6.16.x 
Summary20457: tableExists helper function returns outdated result due to cache
Description

We ran into the issue where on survey activation with closed-access mode and public registration allowed, a database error was thrown if the survey had been activated in open access mode previously. The database error stated that the finaltokens table already existed. Digging deeper, the SurveyAccessModeService->newParticipantTable method was called twice under these exact conditions, once via SurveyActivate->activate and once via SurveyAccessModeService->changeAccessMode. Obviously on the second call the table already existed and $survey->hasTokensTable should have caught that, but no.

So long story short, the tableExists helper in application/helpers/common_helper.php used cached results on the second call, meaning $survey->hasTokensTable was still false and an unsuccessful attempt was made to create the finaltokens table once more.

Steps To Reproduce

Steps to reproduce

  1. Create a new survey and allow public registration.
  2. Activate the survey in open-access mode. Everything should be alright so far.
  3. Deactivate the survey.
  4. Attempt to activate the survey again in closed-access mode.

Expected result

Survey is activated without errors on the second attempt.

Actual result

Survey activation causes a database error.

TagsNo tags attached.
Bug heat8
Complete LimeSurvey version number (& build)6.16.12+26030
I will donate to the project if issue is resolvedNo
Browser
Database type & version-
Server OS (if known)
Webserver software & version (if known)
PHP Version8.3
Git branch / Pull Request URL

Users monitoring this issue

There are no users monitoring this issue.

Activities

riku

riku

2026-03-13 12:01

reporter   ~84452

PR created: https://github.com/LimeSurvey/LimeSurvey/pull/4771

guest

guest

2026-09-15 17:02

viewer   ~85760

Fix committed to master branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&id=40346

c_schmitz

c_schmitz

2026-09-15 17:11

administrator   ~85761

We reverted the commit.
The patch had serious caveats and nobody has been able to reproduce the issue in v7. See my comments in the patch.
@riku can you please check with the latest release version if you can still reproduce the issue on your system?

riku

riku

2026-09-16 09:47

reporter   ~85784

@c_schmitz Indeed, unable to reproduce this in v7 so I guess all good as far as this bug goes.

Now.. the issue only APPEARS to be gone due to the changes made in https://github.com/LimeSurvey/LimeSurvey/pull/4801. But the underlying bugs discovered in my PR are still there, as far as I can tell. On the second call to createTable, the exception is simply ignored due to the try/catch block introduced in c543dd01ecd7b9a646389fde0fa9ed50429858c2 (CDbCommand failed to execute the SQL statement: SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'final_tokens_611668' already exists. The SQL statement executed was: CREATE TABLE final_tokens_611668 ....). The fact that the test itself hasn't changed also confirms this, it is still testing the correctness of invalid logic.

c_schmitz

c_schmitz

2026-09-16 16:17

administrator   ~85793

@riku can you please test the changes from this commit https://github.com/LimeSurvey/LimeSurvey/commit/3006466993d2f6727b53855108e5e832753a0448
and let us know if it fixes the issue?

LimeBot

LimeBot

2026-09-17 13:12

administrator   ~85809

Fixed in Release 7.1.2+260917

riku

riku

2026-09-17 14:29

reporter   ~85824

Yeah seems fine. But the related bugs (including the logic in ImportResponsesTest) are still ignored, might come back to haunt later. The same fix should be applied for SurveyActivator::createResponseTable().

Related Changesets

LimeSurvey: master f495b58b

2026-09-15 16:45

Richard Aljaste

Committer: GitHub


Details Diff
Fixed issue 20457: tableExists helper function returns outdated result due to cache. (04771) Affected Issues
20457
mod - application/helpers/admin/import_helper.php Diff File
mod - application/helpers/common_helper.php Diff File
mod - application/models/services/SurveyDeactivate.php Diff File
mod - tests/functional/backend/ImportResponsesTest.php Diff File

LimeSurvey: master f9c5fb4c

2026-09-15 17:08

eusweisker


Details Diff
Revert "Fixed issue 20457: tableExists helper function returns outdated result due to cache. (04771)"

This reverts commit f495b58baf0dcd2d851b0f57b98ed7068f604ff3.
Affected Issues
20457
mod - application/helpers/admin/import_helper.php Diff File
mod - application/helpers/common_helper.php Diff File
mod - application/models/services/SurveyDeactivate.php Diff File
mod - tests/functional/backend/ImportResponsesTest.php Diff File

Issue History

Date Modified Username Field Change
2026-03-13 11:58 riku New Issue
2026-03-13 12:01 riku Note Added: 84452
2026-03-13 12:01 riku Bug heat 0 => 2
2026-03-18 12:18 c_schmitz Assigned To => c_schmitz
2026-03-18 12:18 c_schmitz Status new => in code review
2026-09-15 16:46 eusweisker Status in code review => resolved
2026-09-15 16:46 eusweisker Resolution open => fixed
2026-09-15 17:02 Changeset attached => LimeSurvey master f495b58b
2026-09-15 17:02 guest Note Added: 85760
2026-09-15 17:03 guest Bug heat 2 => 4
2026-09-15 17:11 c_schmitz Status resolved => feedback
2026-09-15 17:11 c_schmitz Resolution fixed => reopened
2026-09-15 17:11 c_schmitz Note Added: 85761
2026-09-15 17:11 c_schmitz Bug heat 4 => 6
2026-09-15 17:38 eusweisker Changeset attached => LimeSurvey master f9c5fb4c
2026-09-15 17:38 eusweisker Assigned To c_schmitz => eusweisker
2026-09-15 17:38 eusweisker Status feedback => resolved
2026-09-15 17:38 eusweisker Resolution reopened => fixed
2026-09-15 17:38 eusweisker Bug heat 6 => 8
2026-09-15 17:42 c_schmitz Assigned To eusweisker =>
2026-09-15 17:42 c_schmitz Status resolved => feedback
2026-09-15 17:42 c_schmitz Resolution fixed => reopened
2026-09-16 00:57 c_schmitz Bug heat 8 => 6
2026-09-16 09:47 riku Note Added: 85784
2026-09-16 09:47 riku Status feedback => new
2026-09-16 16:17 c_schmitz Note Added: 85793
2026-09-16 16:17 c_schmitz Assigned To => c_schmitz
2026-09-16 16:17 c_schmitz Status new => feedback
2026-09-17 13:12 LimeBot Note Added: 85809
2026-09-17 13:12 LimeBot Status feedback => closed
2026-09-17 13:12 LimeBot Resolution reopened => fixed
2026-09-17 13:12 LimeBot Bug heat 6 => 8
2026-09-17 14:29 riku Note Added: 85824