I want to copy a survey (complex-suvey v0.6) from one subsite to another using the survey_copy proc provided by the package, -new_package_id being the package_id of the target survey package, and I get the following error message:
ERROR: null value in column "tree_sortkey" violates not-null constraint
CONTEXT: PL/pgSQL function "acs_object__new" line 24 at SQL statement
PL/pgSQL function "survey_question__new" line 26 at assignment
SELECT survey_question__new (
As you see, the problem rises when it tries to copy the questions, because when creating the corresponding object, it tries to set a null tree_sortkey.
I've been digging into the code and have found that the place to set the value for this tree_sortkey is the trigger acs_objects_insert_tr. The piece of code that fails to retrieve a correct value for tree_sortkey is this:
SELECT tree_sortkey, tree_increment_key(max_child_sortkey)
INTO v_parent_sk, v_max_child_sortkey
WHERE object_id = new.context_id
where new.context_id is the section_id of the new survey,
and returns null for both v_parent_sk, v_max_child_sortkey.
If I comment in survey_copy the lines involving question copying, the survey and it's sections are copied without problem, and the above select returns not null values. I mean, it seems the problem is that it starts copying the question before the trigger has set the correct tree_sortkey for the parent section (I know, it sounds very inconsistent).
Does anybody know what can be going on?
Note: using the same proc (suvey_copy) to copy surveys within the same survey instance (passing no -new_package_id) works fine, don't know if this helps in the diagnose.
Thanks in advance