Forum OpenACS Development: AMS pkg NULL value

Collapse
Posted by Iuri Sampaio on
I got this bug using AMS pkg. I created a list of extra fields and put in the user form.

Everything seems to work properly execept for the address field. It looks like the api inserts a NULL value when it's a required value field.

just for info:
I used the api to add the elements
ad_form -extend -name user_info -form [ams::ad_form::elements -package_key "acs-admin" -object_type "person" -list_name "extra_fields"]

then to save the values:
ams::values -package_key "acs-admin" -object_id $user_id -object_type "person" -list_name "extra_fields"

and when i fill out the form and submit i got the error.
please help!!!

PAGE: /packages/acs-subsite/lib/user-info
------------------------------------------------------------
Database operation "0or1row" failed (exception NSDB, "Query was not a statement returning rows.")

ERROR: null value in column "delivery_address" violates not-null constraint
CONTEXT: PL/pgSQL function "ams_value__postal_address_save" line 52 at SQL statement

SQL:
select ams_value__postal_address_save (
NULL,
'test',
'test',
'TEST',
'AL',
NULL,
NULL
)

while executing
"ns_pg_bind 0or1row nsdb1 {
select ams_value__postal_address_save (
:delivery_address,
:municipality,
:region,
:postal_code..."
("uplevel" body line 1)
invoked from within
"uplevel $ulevel [list ns_pg_bind $type $db $sql]"
("postgresql" arm line 2)
invoked from within
"switch $driverkey {
oracle {
return [uplevel $ulevel [list ns_ora $type $db $sql] $args]
}
..."
invoked from within
"db_exec 0or1row $db $full_name $sql"
invoked from within
"set selection [db_exec 0or1row $db $full_name $sql]"
("uplevel" body line 2)
invoked from within
"uplevel 1 $code_block "
invoked from within
"db_with_handle -dbn $dbn db {
set selection [db_exec 0or1row $db $full_name $sql]
}"
(procedure "db_string" line 8)
invoked from within
"db_string save_value {} -default {}"
(procedure "ams::util::postal_address_save" line 13)
invoked from within
"ams::util::postal_address_save -delivery_address [template::util::address::get_property delivery_address $value] -municipality [template::util::addr..."
("form_save_value" arm line 3)
invoked from within
"switch $request {
ad_form_widget {
set help_text [attribute::help_text -attribute_id $attribute_id]
if { [string is true $optional..."
(procedure "::ams::widget::postal_address" line 3)
invoked from within
"::ams::widget::${widget} -request $request -attribute_name $attribute_name -pretty_name $pretty_name -value $value -optional_p $optional_p -form_name ..."
(procedure "ams::widget" line 32)
invoked from within
"ams::widget -widget $widget -request "form_save_value" -attribute_name $attribute_name -pretty_name $pretty_name -form_name $form_name -attribute_id $..."
invoked from within
"set value_id [ams::widget -widget $widget -request "form_save_value" -attribute_name $attribute_name -pretty_name $pretty_name -form_name $form_name -..."
("uplevel" body line 2)
invoked from within
"uplevel 1 $code_block "
("1" arm line 1)
invoked from within
"switch $errno {
0 {
# TCL_OK
}
1 {
# TCL_ERROR
..."
("while" body line 20)
invoked from within
"while { [db_getrow $db $selection] } {
incr counter
if { [info exists array_val] } {
unset array_val
..."
("uplevel" body line 5)
invoked from within
"uplevel 1 $code_block "
invoked from within
"db_with_handle -dbn $dbn db {
set selection [db_exec select $db $full_statement_name $sql]

set counter 0
while { [db_getrow $..."
(procedure "db_foreach" line 36)
invoked from within
"db_foreach select_elements {} {
set value_id [ams::widget -widget $widget -request "form_save_value" -attribute_name $attribute_name -pretty_name..."
("uplevel" body line 2)
invoked from within
"uplevel 1 $transaction_code "
(procedure "db_transaction" line 39)
invoked from within
"db_transaction {
db_foreach select_elements {} {
set value_id [ams::widget -widget $widget -request "form_save_value" -attribute_name $attribute..."
(procedure "ams::ad_form::save" line 7)
invoked from within
"ams::ad_form::save -package_key "acs-admin" -object_type "person" -list_name "extra_fields" -form_name "user_info" -object_id $user_id"
("uplevel" body line 35)
invoked from within
"uplevel #$level $on_submit"
("1" arm line 592)
invoked from within
"switch $errno {
0 {
# TCL_OK
}
1 {
# TCL_E..."
(procedure "ad_form" line 612)
invoked from within
"ad_form -extend -name user_info -form {
{url:text,optional
{label "[_ acs-subsite.Home_page]"}
{html {size 50}}
{mode $elm..."
("uplevel" body line 113)
invoked from within
"uplevel {
#
# Expects:
# user_id:optional
# return_url:optional
# edit_p:optional
# message:optional
# show_groups_p:optional

auth::require_log..."
(procedure "code::tcl::/home/conaje/conaje/packages/acs-subsite/lib/user..." line 2)
invoked from within
"code::tcl::$__adp_stub"
invoked from within
"if { [file exists $__adp_stub.tcl] } {

# ensure that data source preparation procedure exists and is up-to-date
adp_init tcl $__adp_stub
..."
("uplevel" body line 3)
invoked from within
"uplevel {

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

# ensure that data source preparation procedure exists and is up-to-date
adp_init t..."
(procedure "adp_prepare" line 2)
invoked from within
"adp_prepare "
(procedure "template::adp_parse" line 30)
invoked from within
"template::adp_parse [template::util::url_to_file "/packages/acs-subsite/lib/user-info" "$__adp_stub"] [list user_id "[ad_quotehtml [lang::util::locali..."

Collapse
2: Re: AMS pkg NULL value (response to 1)
Posted by Malte Sussdorff on
This is easy: Your version of postal address (not the one currently in head) requires that you HAVE to fill out a street when you enter a value for an address.

The new version does not anymore (you can just fill in a country and not have to fill in a street)

Collapse
3: Re: AMS pkg NULL value (response to 2)
Posted by Iuri Sampaio on
That's weird!
- I guess it isn't the reason. I filled out the fields as mnemonic values as you can see at the sql query bellow:

Error in include template "/home/conaje/conaje/packages/acs-subsite/lib/user-info": Transaction aborted: Database operation "0or1row" failed (exception NSDB, "Query was not a statement returning rows.") ERROR: null value in column "delivery_address" violates not-null constraint CONTEXT: PL/pgSQL function "ams_value__postal_address_save" line 52 at SQL statement SQL: select ams_value__postal_address_save ( NULL, 'street', 'state', '407689', 'BR', NULL, NULL )

Just in case!!! I just checkout postal address from cvs HEAD and installed. The bug remains the same.

- plus, why the values that i submited to a text box, they don't show on the list? And the api call is just fine

Collapse
4: Re: AMS pkg NULL value (response to 3)
Posted by Iuri Sampaio on
more info:

in order to prove that the api calls are working:

The api to add the extra fields is fine. The fields are in the user form.

ad_form -extend -name user_info -form [ams::ad_form::elements -package_key "acs-subsite" -object_type "person" -list_name "extra_info"]

and the api to save the values is fine as well

ams::ad_form::save -package_key "acs-subsite" -object_type "person" -list_name "extra_info" -form_name "user_info" -object_id $user_id

i checked the textbox as required submit new values in the form. So if the values weren't being passed the red warning would come up. but it didn;t.

then why the api isn;t working :(
ams::values -package_key "acs-subsite" -object_id $user_id -object_type "person" -list_name "extra_info"

Collapse
5: Re: AMS pkg NULL value (response to 4)
Posted by Iuri Sampaio on
so far i've put a ns_notice at the api just ams::saveto see what value is being passed to value_save

****************************
set value_id [ams::widget -widget $widget -request "form_save_value" -attribute_name $attribute_name -pretty_name $pretty_name -form_name $form_\
name -attribute_id $attribute_id]

ns_log notice "TEST: $attribute_name: $value_id"

ams::attribute::value_save -object_id $object_id -attribute_id $attribute_id -value_id $value_id
*******************************

and the weird message come up on the error.log file
I was expecting to come TEST: followed with the fields that are on ams-list

*************************************
[20/Feb/2007:06:06:18][10468.49156][-conn:conaje::0] Notice: TEST: aol_msg:
NOTICE: adding missing FROM-clause entry for table "acs_object_id_seq"
CONTEXT: PL/pgSQL function "acs_object__new" line 17 at select into variables
PL/pgSQL function "acs_object__new" line 11 at return
PL/pgSQL function "ams_value__postal_address_save" line 43 at assignment
[20/Feb/2007:06:06:18][10468.49156][-conn:conaje::0] Error: Ns_PgExec: result status: 7 message: ERROR: null value in column "delivery_address" violates not-null constraint
CONTEXT: PL/pgSQL function "ams_value__postal_address_save" line 52 at SQL statement

[20/Feb/2007:06:06:18][10468.49156][-conn:conaje::0] Error: Error in include template "/home/conaje/conaje/packages/acs-subsite/lib/user-info": Transaction aborted: Database operation "0or1row" failed (exception NSDB, "Query was not a statement returning rows.")

ERROR: null value in column "delivery_address" violates not-null constraint
CONTEXT: PL/pgSQL function "ams_value__postal_address_save" line 52 at SQL statement
...

Collapse
6: Re: AMS pkg NULL value (response to 5)
Posted by Iuri Sampaio on
Hi MAlte,
good news! Somehow i fixed the error. The fileds were inserted using the same proc i was using before, but i changed the list_name to extended_fields. Somehow it worked!

ad_form -extend -name user_info -form [ams::ad_form::elements -package_key "acs-subsite" -object_type "person" -list_name "extra_info"]

ams::ad_form::save -package_key "acs-subsite" -object_type "person" -list_name "extra_info" -form_name "user_info" -object_id $user_id

Then, I changed the api ams::values -package_key ...
to
ams::ad_form::values -package_key "acs-subsite" -object_id $user_id -object_type "person" -list_name "extra_info"

However i did update the pkgs ams and postal-address and the NULL sql error's still there.
are you sure the version commited is ok??

Collapse
7: Re: AMS pkg NULL value (response to 6)
Posted by Malte Sussdorff on
Hi Iuri, i am pretty sure it works. Just look in the postgresql/upgrade directory. If there is nothing there, make a new checkout. You should see this file:
http://cvs.openacs.org/cvs/openacs-4/packages/postal-address/sql/postgresql/upgrade/
Collapse
8: Re: AMS pkg NULL value (response to 7)
Posted by Iuri Sampaio on
hi Malte,

I found the file, i just ran
psql -f conaje/packages/postal-address/sql/postgresql/upgrade/upgrade-0.2d1-0.2d2.sql conaje

and it worked out. I can leave street blank and it doesn;t return any error.

Although the file were there, i didn't see on the GUI (browser) the option to upgrade it.

I was wondering what makes some packages such as ams pkg shows up at the upgrade pkg GUI section.

So how does the kernel recognize the ones to upgrade.

I know the wise developer has to trust in the code instead of the eyes. :)
So i went to the server and both pgks have the same hierarchy of directories.