View Issue Details

This bug affects 1 person(s).
 4
IDProjectCategoryView StatusLast Update
18394Bug reportsSurvey editingpublic2022-10-12 01:30
Reportergabrieljenik Assigned To 
PrioritynoneSeveritypartial_block 
Status confirmedResolutionopen 
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 heat4
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

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

manager   ~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

manager   ~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

manager   ~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.

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