Forum OpenACS Development: Error in site_node_apm_integration::get_child_package_id

At the moment I can see two problems with the current implementation:
1. Function call with a package_id which is mounted on more than one site node will fail.
2. Function call with a package_key which is mounted more than once bellow the parrent node will fail.

To solve the problem I would suggest the following two changes:

1. Change query:
    Current query
    <fullquery name="site_node_apm_integration::get_child_package_id.select_child_package_id">
        <querytext>
            select sn1.object_id
            from site_nodes sn1,
                apm_packages
            where sn1.parent_id = (select sn2.node_id
                                  from site_nodes sn2
                                  where sn2.object_id = :package_id)
            and sn1.object_id = apm_packages.package_id
            and apm_packages.package_key = :package_key
        </querytext>
    </fullquery>

    Suggested query
    <fullquery name="site_node_apm_integration::get_child_package_id.select_child_package_id">
        <querytext>
            select DISTINCT sn1.object_id
            from site_nodes sn1,
                apm_packages
            where sn1.parent_id IN (select sn2.node_id
                                  from site_nodes sn2
                                  where sn2.object_id = :package_id)
            and sn1.object_id = apm_packages.package_id
            and apm_packages.package_key = :package_key
        </querytext>
    </fullquery>

2. Change function body:
  Replace
  return [db_string select_child_package_id {} -default ""]
  with
  return [db_list select_child_package_id {}]

As the current implementation did not work for multiple result entries, the db_list shouldn't effect existing function calls off this function.

Many thanks
Patrick

Patrick,

if i see correctly, this is not a problem of the "current implementation", but the interface was designed that way. The documentation speaks clearly about a singular package_id, and there are at least 8 places in the sources of the packages in the oacs-5-8 tree, where a variable package_id (singular) is assigned and where the code assumes at most one value.

So, this change is not a simple fix (i.e. for the oacs-5-8 branch), but a function extension, that should be probably tipped, and should go into head. Most probably the best way for such a feature integration is to
- create a new function returning potentially a list of package_ids,
- mark the existing function as deprecated
- use the plural version in the packages where the old one was used so far and add some sane semantics for multiple results.

Thanks for your quick reply. May we should not invest too much time, because my scenario is quite specific. I call the function "calendar::item::edit" from my own package (outside the calender package) to edit existing appointments in the personal calendar. Additionally to that, my package instance is mounted on three different site nodes. Altogether results in the described error.

Calling stack:

calendar::item::edit
  => calendar::do_notifications
      => calendar::item::get
        => calendar::attachments_enabled_p
            => site_node_apm_integration::child_package_exists_p
              => site_node_apm_integration::get_child_package_id (subquery will fail, db_transaction in calendar::item::edit will rollback)

An ugly hack would be to call "ad_conn -set package_id" with a different package_id prior call of calendar::item::edit. That would work, but I tried to avoid that.

Many thanks
Patrick