View Issue Details

This issue affects 1 person(s).
 8
IDProjectCategoryView StatusLast Update
18394Bug reportsSurvey editingpublic2026-10-20 17:06
Reportergabrieljenik Assigned Toc_schmitz  
PrioritynoneSeveritypartial_block 
Status closedResolutionfixed 
Product Version5.3.x 
Summary18394: Sometimes, when creating/copying questions, code dump can ocurr
Description

Caught while reviewing 18323.
Sometimes $oQuestion->survey is throwing an error.

models/QuestionTypes.php

    public function applyToQuestion($oQuestion)
    {
        $this->question = $oQuestion;
        $aSettingsArray = self::modelsAttributes($oQuestion->survey->language)[$oQuestion->type];
        foreach ($aSettingsArray as $settingKey => $setting) {
            $this->$settingKey = $setting;
        }
    }

Sometimes, when creating a question, wrongly, it may happen that the survey is not ready associated to a question.

  • The CopyQuestion service creates the question and sub-questions by directly setting the "attributes" property. (that was fixed on 18323, undo it to trigger the error please :) )
  • That triggers the execution of rules() because it has to determine the safe attributes.
  • Since rules() is executed before the attributes are set, when it gets to applyToQuestion() and it tries to access $oQuestion->survey->language, the relationship with Survey doesn't work because the SID is still 0.

Fix:

  • If survey is not set, use null as language to be sent as parameter.
Steps To Reproduce

Same as in 18323
Debug a bit to be able to see the error.

I understand this is very difficult to reproduce on other situations and maybe, will not happen on other situations.
Still, I guess it is a good practice to make the method more robust

TagsNo tags attached.
Bug heat8
Complete LimeSurvey version number (& build)5.3.30
I will donate to the project if issue is resolvedNo
BrowserOpera
Database type & versionmariadb Ver 15.1 Distrib 10.4.25-MariaDB, for Linux (x86_64) using readline 5.1
Server OS (if known)
Webserver software & version (if known)
PHP Version7.4
Git branch / Pull Request URL

Relationships

related to 18323 closedgabrieljenik When copying a question with sub-questions, the sub-questions are not copied 
related to 18404 closedgabrieljenik Error after copying question: Trying to property 'language' of non-object 

Users monitoring this issue

There are no users monitoring this issue.

Activities

DenisChenu

DenisChenu

2022-10-04 15:17

developer   ~72081

If we set question->sid before other atttributes ?
It don't work ?

Else sid can not be empty when save, rules didn't go by order ?
Can not reorder rules ?

gabrieljenik

gabrieljenik

2022-10-04 15:20

developer   ~72083

That would be a workaround.
I believe the fix is to create function rules.

Don't believe it is good to rely on a way to use a model to not trigger a dump.

gabrieljenik

gabrieljenik

2022-10-04 15:21

developer   ~72085

Ex: https://www.yiiframework.com/wiki/168/create-your-own-validation-rule

DenisChenu

DenisChenu

2022-10-04 15:22

developer   ~72086

I believe the fix is to create function rules.

I don't understand

If survey is not set, use null as language to be sent as parameter.

When you save a question sid must be set and survey must exist
You mean we need to set sid and reload related survey after set it ?

DenisChenu

DenisChenu

2022-10-04 15:23

developer   ~72088

I believe the fix is to create function rules.

OK : replace the current validation by specific function : this make easier to understand and fix : Yes :+1:

gabrieljenik

gabrieljenik

2022-10-04 15:24

developer   ~72089

When you save a question sid must be set and survey must exist

Validators are usually run before saving, but not always, as it is the case on 18323.

c_schmitz

c_schmitz

2026-10-13 21:49

administrator   ~86441

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

LimeBot

LimeBot

2026-10-20 17:06

administrator   ~86604

Fixed in Release 7.7.0+261020

Related Changesets

LimeSurvey: master 2f8f0dac

2026-10-13 21:49

c_schmitz


Details Diff
Fixed issue 18394: Creating or copying a question could end in a PHP error if the question was validated before its survey was set Affected Issues
18394
mod - application/models/Question.php Diff File
mod - application/models/QuestionType.php Diff File

Issue History

Date Modified Username Field Change
2022-10-04 14:52 gabrieljenik New Issue
2022-10-04 14:52 gabrieljenik Issue generated from: 18323
2022-10-04 14:52 gabrieljenik Relationship added related to 18323
2022-10-04 14:53 gabrieljenik Status new => confirmed
2022-10-04 14:55 gabrieljenik Description Updated
2022-10-04 14:55 gabrieljenik Steps to Reproduce Updated
2022-10-04 15:17 DenisChenu Note Added: 72081
2022-10-04 15:17 DenisChenu Bug heat 0 => 2
2022-10-04 15:20 gabrieljenik Note Added: 72083
2022-10-04 15:20 gabrieljenik Bug heat 2 => 4
2022-10-04 15:21 gabrieljenik Note Added: 72085
2022-10-04 15:22 DenisChenu Note Added: 72086
2022-10-04 15:23 DenisChenu Note Added: 72088
2022-10-04 15:24 gabrieljenik Note Added: 72089
2022-10-12 01:30 gabrieljenik Relationship added related to 18404
2026-10-13 21:49 c_schmitz Changeset attached => LimeSurvey master 2f8f0dac
2026-10-13 21:49 c_schmitz Note Added: 86441
2026-10-13 21:49 c_schmitz Assigned To => c_schmitz
2026-10-13 21:49 c_schmitz Status confirmed => resolved
2026-10-13 21:49 c_schmitz Resolution open => fixed
2026-10-13 21:49 c_schmitz Bug heat 4 => 6
2026-10-20 17:06 LimeBot Note Added: 86604
2026-10-20 17:06 LimeBot Status resolved => closed
2026-10-20 17:06 LimeBot Bug heat 6 => 8