Forum OpenACS Development: Re: ad_page_contract optional default will clober a local var value

Jun, I know what it is like to search through a bunch of code to figure out why my code isn't working. If the problem happens to be in the core, I usually change it, because that is what I need for my stuff to work.

I think the hard decision comes when you want to apply your logical and working fix to the cvs copy.

Possibly a temporary fix to avoid changing your core copy is to create a package which loads after the core and replaces the proc which has the offending logic. I did this the other day for ns_getform.

It seems to be a fine line between improving the toolkit and frustrating other developers that don't have the time to keep up with all the changes, and the reasons for the change.

But here is what I understood from reading your original post. Somehow a variable exists before ad_page_contract is called. Now, what is the purpose of ad_page_contract? The purpose is to enforce the interface to that page. It's a contract. The behavior you describe seems to support the intended behavior of ad_page_contract. It should be clear from reading the tcl page which contains ad_page_contract that a variable is either supplied in the query, or a specified default is used. Now, if you start adding in your own stuff and sourcing this page in some other way, or including it in another page, why would anyone expect it to work the way they wanted it to. So if ad_page_contract was changed to use some other value, hunting down bugs would be very difficult. Future developers would have no way of knowing, by looking at the page, what values might end up there, without the current behavior.

Also, if this is changed, what is ad_page_contract supposed to do: validate the data already present in the variable with the filters specified?

An additional feature of ad_page_contract is to complain if you supply two copies of a variable. I'm not sure you will find an easy solution to determine when a variable came from some other location (the place you wanted it to) or from a buggy form. If it just uses the current value, that means ad_page_contract no longer complains when a form submits two values for one variable. The result is, again, a very hard to find bug, this time in a form.

I really think we need to try to limit the use of ad_page_contract for its intended purpose, which is to document and enforce the interface to the page.