Forum OpenACS Development: Using ad_conn in and outside HTTP connections

Currently ad_conn will error out when called outside an HTTP connection (for example from a Tcl proc during startup). I was thinking that we should be more forgiving by returning the empty string if we are outside a connection. Or should we demand that developers check [ad_conn isconnected] before invoking say [ad_conn user_id]?
Collapse
Posted by Don Baccus on
I strongly dislike silent failures so I'd vote for making them check for a connection ... that would be more readable than today's solution (using catch around an ad_conn call)
Collapse
Posted by Tom Jackson on

Library code should not use ad_conn unless it deals with something requiring a conn. Just because the data is in ad_conn doesn't mean that is the place to get it in every circumstance. Maybe we should identify things that shouldn't be in ad_conn and remove them if that is the problem, or provide built in workarounds inside ad_conn so it can find some data not related to a conn. But I have seem some library code using ad_conn for no good reason. The Calendar package has that problem, or had it.

Collapse
Posted by Lars Pind on
Tom,

What's the calendar package using ad_conn for?

I think that for user_id, it's okay to return 0 as in "no user logged in" when there's no connection. For other things, like package_key, package_id, etc., I'd bomb.

/Lars

Collapse
Posted by Tom Jackson on

Lars,

Of all places: calendar_create hard codes:

  • package_id using [ad_conn "package_id"]
  • creation_ip using [ad_conn "peeraddr"]
  • creation_user using [ad_conn "user_id"]

    Also, adjust_calendar_list gets user_id and package_id, but you can pass in those parameters, so it works.