I found part of code that is causing the error.
It has even a commentary about it.
# Create the entry in user_preferences.
# This only works if we drop the constraint on users.
db_dml insert_preference {
insert into user_preferences (user_id, locale)
select :party_id as user_id, :locale as locale
from dual
where not exists (select 1 from user_preferences where user_id = :party_id)
}
The error happens because it searches for an user_id while the object_type of the respective object_id in this context is an organization instead. So it looks for an inexistent user.
I have to add an organization also has a member of the system in order to fix the error. Also this is what i want to achieve: "having orgs as members"
I put the API to create a new user:
#Create user with user_id equals to organization_party_id
db_transaction {
array set creation_info [auth::create_user \
-user_id $organization_party_id \
-first_names $name \
-last_name $name \
-email $email \
]
}
as expected, that caused a duplicated acs_object_id . Since organizations were also inserted on table acs_objects before by the API organization::new as object_type 'organization'
it is clear to force organization as user in the system causes too many collateral problems.
What would be a solution then?
Database operation "0or1row" failed
(exception ERROR, "ERROR: duplicate key violates unique constraint "acs_objects_object_id_pk"
CONTEXT: SQL statement "insert into acs_objects (object_id, object_type, title, package_id, context_id, creation_date, creation_user, creation_ip, security_inherit_p) values ( $1 , $2 , $3 , $4 , $5 , $6 , $7 , $8 , $9 )"
PL/pgSQL function "acs_object__new" line 39 at SQL statement
PL/pgSQL function "party__new" line 12 at assignment
PL/pgSQL function "person__new" line 14 at assignment
PL/pgSQL function "acs_user__new" line 28 at assignment
PL/pgSQL function "acs__add_user" line 21 at assignment
")
while executing
"ns_pg_bind 0or1row nsdb0 {
select acs__add_user(
:user_id,
'user',
now(),
..."
("uplevel" body line 1)
invoked from within
"uplevel $ulevel [list ns_pg_bind $type $db $sql]"
invoked from within
"db_exec 0or1row $db $full_statement_name $sql"
("uplevel" body line 8)
invoked from within
"uplevel 1 $code_block "
invoked from within
"db_with_handle -dbn $dbn db {
# plsql calls that are simple selects bypass the plpgsql
# mechanism for creating anonymous fun..."
(procedure "db_exec_plsql" line 57)
invoked from within
"db_exec_plsql user_insert {}"
("uplevel" body line 3)
invoked from within
"uplevel 1 $transaction_code "
(procedure "db_transaction" line 1)
invoked from within
"db_transaction {