Forum OpenACS Q&A: how to create a new group?

Request notifications

Collapse
Posted by Benjamin Brink on
Hi,

I'm trying to create an acs_object_id for future use as a contact within the context of a package_id. So, I'm attempting to do something like:

set instance_id [ad_conn package_id]
set id [application_group::new -package_id $instance_id -group_name "test 1"]

which appears similar to use in contacts package.

Given a fresh database install on openacs-core from github I get the below error for:
acs-kernel 5.9.0 from around 2015-03-30,
and
acs-kernel 5.9.1b5 from today.

Error: nsdbpg: result status: 7 message: ERROR: duplicate key value violates unique constraint "application_groups_package_id_un"
DETAIL: Key (package_id)=(639) already exists.
CONTEXT: SQL statement "insert into application_groups (group_id, package_id)
values (v_group_id, new__package_id)"
PL/pgSQL function application_group__new(integer,character varying,timestamp with time zone,integer,character varying,character varying,character varying,character varying,integer,character varying,integer) line 18 at SQL statement

[12/May/2017:00:23:22][4669.7fa199c7a700][-conn:oacs-dev:1-] Notice: -- creating per thread sequence table
[12/May/2017:00:23:22][4669.7fa199c7a700][-conn:oacs-dev:1-] Error: Database operation "0or1row" failed (exception ERROR, "ERROR: duplicate key value violates unique constraint "application_groups_package_id_un"
DETAIL: Key (package_id)=(639) already exists.
CONTEXT: SQL statement "insert into application_groups (group_id, package_id)
values (v_group_id, new__package_id)"
PL/pgSQL function application_group__new(integer,character varying,timestamp with time zone,integer,character varying,character varying,character varying,character varying,integer,character varying,integer) line 18 at SQL statement
")

ERROR: duplicate key value violates unique constraint "application_groups_package_id_un"
DETAIL: Key (package_id)=(639) already exists.
CONTEXT: SQL statement "insert into application_groups (group_id, package_id)
values (v_group_id, new__package_id)"
PL/pgSQL function application_group__new(integer,character varying,timestamp with time zone,integer,character varying,character varying,character varying,character varying,integer,character varying,integer) line 18 at SQL statement

SQL:

select application_group__new (
NULL,
'application_group',
now(),
'704',
'192.25.2.51',
NULL,
NULL,
'test 1',
'639',
null,
'639'
)


while executing
"ns_pg_bind 0or1row nsdb0 {

select application_group__new (
:group_id,
:group_type,
now(),
:creation_us..."
("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 func..."
(procedure "::nsf::procs::db_exec_plsql" line 56)
invoked from within
"db_exec_plsql add_group {}"
("uplevel" body line 3)
invoked from within
"uplevel 1 $transaction_code"
(procedure "::nsf::procs::db_transaction" line 1)
invoked from within
"db_transaction {
# creating the new group
set group_id [db_exec_plsql add_group {}]
}"
(procedure "::nsf::procs::application_group::new" line 30)
invoked from within
"application_group::new -package_id [ad_conn package_id] -group_name "test 1" "
("uplevel" body line 6)
invoked from within
"uplevel {
set content ""
set title "test"

set content [application_group::new -package_id [ad_conn package_id] -group_name "test 1" ]

}"
(procedure "code::tcl::/var/www/oacs-dev//www/testit" line 2)
invoked from within
"code::tcl::$__adp_stub"
("uplevel" body line 12)
invoked from within
"uplevel {

if { [file exists $__adp_stub.tcl] } {

# ensure that data source preparation procedure exists and is up-to-date
..."
(procedure "adp_prepare" line 2)
invoked from within
"adp_prepare"
invoked from within
"template::adp_parse $themed_template {}"
(procedure "adp_parse_ad_conn_file" line 14)
invoked from within
"$handler"
("uplevel" body line 2)
invoked from within
"uplevel $code"
invoked from within
"ad_try {
$handler
} ad_script_abort val {
# do nothing
}"
invoked from within
"rp_serve_concrete_file [ad_conn file]"
(procedure "::nsf::procs::rp_serve_abstract_file" line 60)
invoked from within
"rp_serve_abstract_file "$root/$extra_url""
("uplevel" body line 2)
invoked from within
"uplevel $code"
invoked from within
"ad_try {
rp_serve_abstract_file "$root/$extra_url"
set ::tcl_url2file([ad_conn url]) [ad_conn file]
se..."
called from rp_handler

Collapse
Posted by Gustaf Neumann on
The commands look fine; i tested just now
set instance_id [ad_conn package_id]
set id [application_group::new -package_id $instance_id -group_name "test 1"]
which returns 1508. In the DB i see
oacs-5-9-1=# select * from application_groups;
 group_id | package_id 
----------+------------
       -2 |        639
     1502 |           
     1508 |       1110
(3 rows)
so, all is fine. If you look at the error message, you have posted, there is the following line:
ERROR: duplicate key value violates unique constraint "application_groups_package_id_un"
... which means, there is already an application group with the same package_id in your system - there can be only one application group per package_id; check in your DB...

all the best

Collapse
Posted by Benjamin Brink on
Aha! Thank you, Gustaf.

One application_group per package. That explains the duplicate key.

Time to study on how contacts package uses groups.. and works in general