Forum OpenACS Development: Getting package_id in tcl scripts

Collapse
Posted by Vinod Kurup on
I was trying to make an automated test for the etp package and I noticed that etp::make_page gets package_id like this:
set package_id [ad_conn package_id]
Unfortunately, when you try to call this from an automated test, [ad_conn package_id] returns the package_id of the acs_automated_testing instance, not your etp instance.

This could also be a problem when making your package XML-RPC aware - [ad_conn package_id] would be the xml-rpc package_id, not your desired package_id.

So, I'm wondering if we should state that tcl procs that need package_id should allow it to be passed in and use [ad_conn package_id] only if the passed in var was empty.

Collapse
Posted by Dave Bauer on
Vinod,

I agree. Another point is that the procedure should check if there is an active connection before calling [ad_conn package_id] by calling [ad_conn connected_p]. Tcl procedures should accept a package_id parameter if they need the package_id. Same with user_id. Generally you want to avoid making ad_conn calls in tcl procedures if you can. This isn't always possible, but it makes it a little easier to allow the procedures to be called from a scheduled procedure or in an automated test.