Forum OpenACS Development: Title before name_method

Collapse
Posted by Malte Sussdorff on
The script ./upgrade-5.10.0d21-5.10.0d22.sql modifies the acs_object.name behavior to prioritize the title attribute over the name_method when available. This approach is thoughtful, considering that titles often provide a more descriptive label for objects.

However, looking at object_creation
--
IF new__title IS NULL THEN
SELECT pretty_name INTO v_object_type_pretty_name
FROM acs_object_types
WHERE object_type = new__object_type;

v_title := v_object_type_pretty_name || ' ' || v_object_id;
ELSE
v_title := new__title;
END IF;
--

From the above, it appears that a default title is always set for new objects, either directly or derived from the pretty_name. This could imply that the name_method, which might be intended as a fallback or alternative naming mechanism, is seldom utilized.

Is this on purpose? If yes, we would have to write our own im_object__name function to keep the old behavior, as project open heavily relies on the name_method.

Collapse
Posted by Malte Sussdorff on
An alternative could be to only use the title, if there is no name_method like this:

select title into object_name
from acs_objects o, acs_object_types ot
where object_id = name__object_id
and ot.object_type = o.object_type
and ot.name_method is null;

(which should work in ]project-open[). But this might not work in general if OpenACS wants to sunset the name_method

Collapse
Posted by Antonio Pisano on
Dear Malte,

I think "downgrading" the name method was not intentional and would be actually better to have an approach similar to your suggestion.

Will let you know shortly

Collapse
Posted by Antonio Pisano on
Mmm, needs a bit of thinking:

first of all, according to the git history, this behavior is much older than the reform you have been referring to. The reform in acs_object__name prioritizing the title instead of the name method is some 21 years old: https://github.com/openacs/openacs-core/blame/719a4a4fe58dd082e7dccfaed805125337b10d41/packages/acs-kernel/sql/postgresql/acs-objects-create.sql#L767-L774

Similarly, the behavior concerning the title in acs_object__new is also quite old: https://github.com/openacs/openacs-core/blame/719a4a4fe58dd082e7dccfaed805125337b10d41/packages/acs-kernel/sql/postgresql/acs-objects-create.sql#L492-L502

In current codebase, for the name method to trigger, the object's title must be null. This won't happen automatically, given that we always fallback to the object type's pretty name + id. We could change that , e.g. let the title be null when not specified explicitly.

Another approach is to switch the priority when we retrieve the name, e.g. name method first and object title as a fallback.

Personally, I tend to prefer the first approach: we would store less data for those use cases where the object's title is not important, keep current behavior if the object's title matter, and give the name method a fair chance to trigger.

I am open to discussion, but as this has the potential to be a breaking change, we should consider if it should make it into the release or not.

Ciao

Collapse
Posted by Gustaf Neumann on
let the title be null when not specified explicitly.

Malte: would this help for PO? i.e., does PO set the title attribute and uses the object.name method on the same entities? Does this happen just on PO-specific acs_object_types?

Collapse
Posted by Malte Sussdorff on
let the title be null when not specified explicitly.

Yes. this would help indeed. Though this would have to propagate through the acs_object.new function, which sets a default title.

Then the order would make sense - Use title if set, use object.name otherwise.

We would need an upgrade script which resets the title to "null" if the title is the default name set by acs_objects.new

Collapse
Posted by Malte Sussdorff on
I dug around in project-open code and found that project-open overwrote the acs_object__name function, so uncomment the part where it first looks at the name method. Probably 21 years ago 😊.

Either way, we should avoid a breaking change. Therefore we could have an upgrade script which:

- Changes acs_object.new to not set a default title
- Delete the title wherever the title = default title

Two options
- Set the name method to a new method which preserves the old "default" behavior, (e.g. acs_object.default_title) where the name_method is empty, and make name_method mandatory. This will make it very clear which naming method is used, if title is not overwritten.
- Change the acs_object.name method to default to the old default title if the title is NULL and the name_method is NULL.