Forum OpenACS Development: ad_conn and no connection

Collapse
Posted by Malte Sussdorff on
I have been asked a couple of times, why does ad_conn return an error when there is no connection, and if this is the case, why doesn't it state so on a prime position in the documentation. New people expect (and this does include me, though I know from working for years with OpenACS that it does not work that way) that, if there is no connection, than the value should be empty.

I personally agree and to my knowledge ns_conn usually does not return empty values when there is a connection, but as this would break backward compatability I think we are stuck with it.

Don pointed out the following:

""ns_conn isconnected returns 1 if you're in a connection thread, and you are therefore allowed to make calls to ns_conn. It returns 0 if you're not in a connection thread (such as when you're in a scheduled procedure) and you are not allowed to make calls to ns_conn."

You're supposed to check if the connection exists (you can use [ad_conn isconnected] for consistency) before calling ns_conn, and if you don't, and isconnected is 0, you get an error."

Collapse
Posted by Dave Bauer on
If you need to check, it can indicate that your code is calling ad_conn in the wrong place.

If possible you should pass in the values of ad_conn to your tcl apis and only call ad_conn from places where you would expect to have a connection, ie: a tcl/adp page.

Collapse
Posted by Christian Brechbuehler on
You bet my code is calling it in the wrong place 😊
I just don't know where it goes wrong.

The scheduled search::indexer calls bug_tracker::search::bug::datasource, and that calls ad_conn, which causes an error. (See my comment on ad_conn breaks all scheduled procs. Happy to post the whole call chain, if it helps.)

Quite likely I'm going about this the wrong way. I'm using code from OpenACS and am trying to make it work. Maybe I should enter a bug against package acs-subsite, because its procs use ad_conn? My patch simply assumes the main site (aka root) when there's no connecton -- not sure if that's correct.

It would help if every proc documented clearly whether it requires a connection, or if it's also ok to call it from a scheduled proc. We could postulate that a conn-only proc can call either, but a general proc can only call other general procs. That would make it clearer where things go wrong.

Collapse
Posted by Dave Bauer on
I think there is a BUG in the procedure that gets a community url for a user. That was introduced after the bugtracker code was written.

In general NEVER call ad_conn from a procedure, unless you have a very good reason. I think the code you are referring to where you assume the main subsite, is the same thing I did to make bugtracker search work on openacs.org.

It need a real fix for multiple subsites.

Collapse
Posted by Christian Brechbuehler on
Thanks, Dave!

Blunt question: what's a community?

I've come across community_id here and there, and it looks like a dotLRN thing. E.g., SQL trying to access column community_id in table site_wide_index fails, because there is no such column in the data model (non-dotLRN). I'm kludging the API discrepancies by passing around 0, but it doesn't feel like the right approach.

As I recently asked in a separate thread: Does community have any meaning outside dotLRN?
If yes, how does "community" relate to the good old "subsite"?

BTW, I have two bug_tracker instances, and the hack of always assuming main site gives me the correct, distinct URLs in search results.

Collapse
Posted by Dave Bauer on
Community in this sense is the concept that OpenACS is the toolkit for online communities.

I was referring to this procedure http://www.openacs.org/api-doc/proc-view?proc=acs%5fcommunity%5fmember%5furl

or someting like it, I did not go poking around in bug-tracker.

I guess the analogous thing in openacs to a .LRN community is a subsite and all the packages underneath it.

If you have two bugtracker instances in the main subsite, you don't have to worry about it.