edgarrmondragon / citric

A client to the LimeSurvey Remote Control API 2, written in modern Python.
https://citric.rtfd.io
MIT License
26 stars 8 forks source link

[Bug]: set_question_properties returns "No valid data" on nested attributes #1110

Open soberhofer opened 7 months ago

soberhofer commented 7 months ago

Citric Version

1.0.0

Python Version

3.10

LimeSurvey Version

6.4.10

Backend database

Limesurvey Hosted

Operating System

Limesurvey Hosted

Description

I am trying to programmatically update the answer_order of all questions in a survey to random.

I have confirmed I can update other properties such as title using

props: types.QuestionProperties = {'title': 'test'}
client.set_question_properties(question['id'], language="en", **props)

but when I try

props: types.QuestionProperties = {'attributes': {'answer_order': 'random'}}
client.set_question_properties(question['id'], language="en", **props)

I get No valid Data

is setting nested properties not supported? I couldn't find anything in the documentation.

Code

No response

Permissions Matrix

No response

edgarrmondragon commented 7 months ago

Hi @soberhofer, thanks for filing!

Unfortunately, the RemoteControl API doesn't seem to support it: https://forums.limesurvey.org/forum/development/134557-rpc-api-set-attributes-with-set_question_properties#241626.

The workaround recommended in that thread is to use import_question^1 with question files edited by other means:

with open("my_question_file.lsq", "rb") as file:
    client.import_question(file, survey_id=..., group_id=...)

For question types where it's relevant, you should be looking for a random_order attribute I think:

   <row>
    <qid><![CDATA[207]]></qid>
    <attribute><![CDATA[random_order]]></attribute>
    <value><![CDATA[1]]></value>
    <language/>
   </row>
edgarrmondragon commented 7 months ago

And FWIW I've wanted to add features to this library to help programmatically construct XML for questions and surveys but it seems daunting since the schema is undocumented ... and it's XML 😅

soberhofer commented 7 months ago

Thank you very much for your input. I guess i'll have to to programmatically edit the lsq or the lsg, and then import it that way. Yeah, daunting is the right word. :D