View Issue Details

This bug affects 1 person(s).
 6
IDProjectCategoryView StatusLast Update
17169Bug reportsPluginspublic2021-03-10 07:59
ReporterMazi Assigned Toc_schmitz  
PrioritynormalSeveritypartial_block 
Status closedResolutionwon't fix 
Product Version3.25.17 
Summary17169: QuestionAttribute::model()->findByAttributes() only returns DB values which does NOT include default values
Description

This code should return the assessment value set at the "logic" section of a multi choice question:
$questionAttribute = QuestionAttribute::model()->findByAttributes([
'qid' => $questionId,
'attribute' => 'assessment_value'
]);
$assessmentValue = intval($questionAttribute->attributes['value']);

If works fine if you set the value to 2 or 5 or 10 or whatever.
PROBLEM: If you set the value to 1, which is the default value, nothing is returned at all. This causes custom plugin code reading the attribute value to break. There simply is no value available.

Steps To Reproduce

Use the above code for a given multi choice question and check the return value.

Additional Information

See Discord chat from 2021-03-09 15:30h

Mazi:
Hey experts, any idea why I am not able to retrieve valid data if the assessment value is set to "1" at a multi chocie question when I am using this code?
$questionAttribute = QuestionAttribute::model()->findByAttributes([
'qid' => $questionId,
'attribute' => 'assessment_value'
]);
If the value is set to 2 or 5 or 10 or whatever, I can get the value using
$assessmentValue = intval($questionAttribute->attributes['value']);
if the value is set to 1, just nothing is returned.

TagsNo tags attached.
Bug heat6
Complete LimeSurvey version number (& build)Version 3.25.17+210309
I will donate to the project if issue is resolvedNo
BrowserChrome
Database type & versionMySQL 5
Server OS (if known)Ubuntu 18
Webserver software & version (if known)Apache
PHP Version7.3

Relationships

related to 16669 closedgabrieljenik Bug reports getQuestionAttributes function don't get the plugins attribute 
related to 14228 confirmed Feature requests Survey and Question Theme need more information 
related to 14248 acknowledged Feature requests Allow survey theme to add (and use) question attribute 

Users monitoring this issue

There are no users monitoring this issue.

Activities

jelo

jelo

2021-03-09 15:38

partner   ~62947

It sounds wise to save the default value in the responses table. And not construct the data. If the code changes, the default value might change. To be sure about what value was chosen when the survey was conducted save the default value to the database. The additional storage is not wasted.

You don't want to have the return of no data as an proxy for default data. That sounds like begging for issues in the long run.

Keep it simple stupid. If storage is an issue, LimeSurvey should start with the session size abuse ;-)

DenisChenu

DenisChenu

2021-03-09 15:48

developer   ~62948

QuestionAttribute::model()->findByAttributes() only returns DB values

yes : it's the definition … https://www.yiiframework.com/doc/api/1.1/CActiveRecord#findByAttributes-detail

If need a getQuestionAttribute near https://github.com/LimeSurvey/LimeSurvey/blob/12cd8e5a2ca9975a3a45a0b10ca0630344d55e7d/application/models/QuestionAttribute.php#L210 : good

I already make a feature request near this : https://bugs.limesurvey.org/view.php?id=14228 or https://bugs.limesurvey.org/view.php?id=14248 some year ago.

It sounds wise to save the default value in the responses table. And not construct the data. If the code changes, the default value might change. To be sure about what value was chosen when the survey was conducted save the default value to the database. The additional storage is not wasted.

It work like this for years , and we never have issue reported … but why not. It's the case (when you save question) in 4.X currentlyè

Else : it make bigger lss size. To test :

  1. Import https://github.com/LimeSurvey/LimeSurvey/blob/master/docs/demosurveys/ls3_sample_survey_multilingual_fr_de_en_it.lss in 4.X
  2. Goes to each question and save value
  3. Export : compare size.
DenisChenu

DenisChenu

2021-03-09 16:18

developer   ~62955

My opinion :

  1. Create a getQuestionAttribute($qid,$attribute, $language = null) : return DB value or default value if not set, by current language or set if i18n
  2. Add it in LimeSurvey API
  3. Add it in TwigRender function

Then :

  1. Plugin dev are happy, they have something fixed
  2. QuestionTheme dev are happy : they have something
c_schmitz

c_schmitz

2021-03-09 21:05

administrator   ~62981

Saving all the values in the database does not make sense either, because saving redundant values is also a bad idea.
Use the functions (getQuestionAttributes) from the model and you are good.

DenisChenu

DenisChenu

2021-03-10 07:59

developer   ~62984

Saving all the values in the database does not make sense either, because saving redundant values is also a bad idea.

It's the case in 4.4, need to report ?

With ls3_sample_survey_multilingual_fr_de_en_it lss file updated maybe ?

Issue History

Date Modified Username Field Change
2021-03-09 15:34 Mazi New Issue
2021-03-09 15:38 ollehar Severity block => partial_block
2021-03-09 15:38 ollehar Priority none => normal
2021-03-09 15:38 jelo Note Added: 62947
2021-03-09 15:48 DenisChenu Note Added: 62948
2021-03-09 16:18 DenisChenu Note Added: 62955
2021-03-09 17:04 Mazi Relationship added related to 16669
2021-03-09 21:05 c_schmitz Assigned To => c_schmitz
2021-03-09 21:05 c_schmitz Status new => closed
2021-03-09 21:05 c_schmitz Resolution open => won't fix
2021-03-09 21:05 c_schmitz Note Added: 62981
2021-03-10 07:58 DenisChenu Relationship added related to 14228
2021-03-10 07:58 DenisChenu Relationship added related to 14248
2021-03-10 07:59 DenisChenu Note Added: 62984