Skip to content

N°9622 - Error in the user story life cycle - #915

Merged
bdalsass merged 6 commits into
developfrom
feature/9622-Linkset_in_transition
Aug 19, 2026
Merged

bdalsass merged 6 commits into
developfrom
feature/9622-Linkset_in_transition

Conversation

@accognet

Copy link
Copy Markdown
Contributor

Internal

@accognet accognet self-assigned this May 21, 2026
@accognet accognet added the internal Work made by Combodo label May 21, 2026
@accognet
accognet requested a review from rquetiez May 21, 2026 08:33
@greptile-apps

greptile-apps Bot commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR changes lifecycle form defaulting for mandatory attributes with a single allowed value. The main changes are:

  • Adds special handling for linkset attributes in DisplayStimulusForm().
  • Loads the current linkset, adds the only allowed object, and writes it back.
  • Leaves scalar defaulting unchanged for non-linkset attributes.

Confidence Score: 3/5

These issues should be fixed before merging.

  • Indirect linksets can load the allowed id from the wrong class and add the wrong link.

  • The creation form still sends a scalar id through the linkset setter path.

  • Both issues affect the single-allowed-value workflow this change is meant to handle.

  • application/cmdbabstract.class.inc.php needs the linkset defaulting paths aligned for direct, indirect, lifecycle, and creation forms.

Important Files Changed

Filename Overview
application/cmdbabstract.class.inc.php Updates single-allowed-value defaulting in lifecycle forms, but the linkset handling is incomplete for indirect links and creation forms.

Comments Outside Diff (1)

  1. application/cmdbabstract.class.inc.php, line 3106-3110 (link)

    P1 Creation form still breaks

    The creation-form path still applies the old scalar defaulting logic to linkset attributes. If a mandatory linkset has exactly one allowed value during object creation, this calls Set() with the scalar id from array_keys(). DBObject::Set() treats non-null linkset values as an object-set iterator and calls UpdateFromCompleteList($value), so the creation form can fail before the user can submit it. This is the same single-allowed-linkset case handled below for lifecycle transitions, but this sibling path remains unchanged.

Reviews (1): Last reviewed commit: "9622 - Error in the user story life cycl..." | Re-trigger Greptile

Comment thread application/cmdbabstract.class.inc.php Outdated
Comment on lines +3243 to +3246
if ($oAttDef->IsLinkSet()) {
$oObjectSet = $this->Get($sAttCode);
$oObjectSet->AddItem(MetaModel::GetObject($oAttDef->GetLinkedClass(), $aValues[0]));
$this->Set($sAttCode, $oObjectSet);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Indirect linksets misload objects

For an AttributeLinkedSetIndirect, GetAllowedValues_att() returns ids from the remote target class, because AttributeLinkedSet::GetValuesDef() uses LinkSetModel::GetTargetClass(). This branch then loads that id from $oAttDef->GetLinkedClass(), which is the link/intermediate class. When a lifecycle transition has exactly one allowed remote object, the form can throw because no link row has that id, or it can add an unrelated existing link row with the same numeric id. The indirect case needs to create a link object and set its remote external key instead of loading the link class by the remote id.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, the proposed solution doesn't work with AttributeLinksetIndirect.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed. Looking at the current diff, it seems the fix has already been updated to simply skip all linksets (!$oAttDef->IsLinkSet()), which is the safe fallback. That avoids the indirect problem entirely.

However, there are two things still worth noting:

1. Direct linksets are also skipped now — for AttributeLinkedSet (non-indirect), the allowed values are ids of GetLinkedClass(), so the original GetObject call would have been correct there. The current fix under-handles that case too.

2. Leftover debug code — there's dead code introduced at line ~3425:

if ($this->GetContext()['objects_to_insert']) {
    $a = $this->GetContext()['objects_to_insert'];
}

This does nothing (assigns to $a which is never used) and should be removed before merge.

For a complete fix of the indirect case, the correct pattern would be:

if ($oAttDef->IsIndirect()) {
    $oLink = MetaModel::NewObject($oAttDef->GetLinkedClass());
    $oLink->Set($oAttDef->GetExtKeyToRemote(), $aValues[0]);
    $oObjectSet = $this->Get($sAttCode);
    $oObjectSet->AddItem($oLink);
    $this->Set($sAttCode, $oObjectSet);
} elseif ($oAttDef->IsLinkSet()) {
    $oObjectSet = $this->Get($sAttCode);
    $oObjectSet->AddItem(MetaModel::GetObject($oAttDef->GetLinkedClass(), $aValues[0]));
    $this->Set($sAttCode, $oObjectSet);
} else {
    $this->Set($sAttCode, $aValues[0]);
}

Whether to implement that or keep the "skip all linksets" approach depends on whether auto-filling linksets during stimulus transitions is a desired behaviour for your use case.

Tip: You can customize Greptile's behavior for this repo with .greptile/rules.md and .greptile/config.json.

Comment thread application/cmdbabstract.class.inc.php Outdated
$this->Set($sAttCode, $aValues[0]);
if ($oAttDef->IsLinkSet()) {
$oObjectSet = $this->Get($sAttCode);
$oObjectSet->AddItem(MetaModel::GetObject($oAttDef->GetLinkedClass(), $aValues[0]));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any way $aValues contains more than one single value?

can you add a test that cover DisplayStimulusForm with this new fixed usecase (linkset), pls.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if GetObject throws an exception when object does not exist? if it could happen, it could be nice for support team to catch the exception, log it and return false (i guess?).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the attribute is a LinkSet, GetAllowedValues_att returns an ObjectSet from an OQL query. Therefore, I believe this object must exist.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And to answer the first question, it is impossible for $Values ​​to contain more than one value, because the test count($allowedValues) == 1 was performed just before.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok technically it is not possible. you are right (count==1).

so functionally this PR fixes stimulus form display of current object, by adding first found allowed value to the linkset, right? no all possible allowed values. one is enough...
if there is one value to add, cant it be default one if it exists? maybe it does not make sense?

@Molkobain Molkobain changed the title 9622 - Error in the user story life cycle N°9622 - Error in the user story life cycle Jun 17, 2026
@Molkobain

Copy link
Copy Markdown
Member

I discussed this fix with @rquetiez, we need to dig deeper into the cause. For now we focus on the 3.3.0-beta, discussion will be done afterwards.

Copilot AI balanced review requested due to automatic review settings August 19, 2026 06:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes lifecycle transition errors caused by auto-selecting a sole link-set value.

Changes:

  • Excludes link sets from automatic value assignment.
  • Adds an ineffective context lookup that can trigger warnings.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread application/cmdbabstract.class.inc.php Outdated
- do not perform prefill on stimulus for linksets
@bdalsass
bdalsass force-pushed the feature/9622-Linkset_in_transition branch from fceccb0 to 52c7226 Compare August 19, 2026 06:18
@bdalsass
bdalsass merged commit 2603377 into develop Aug 19, 2026
@bdalsass
bdalsass deleted the feature/9622-Linkset_in_transition branch August 19, 2026 06:22
@Molkobain Molkobain added this to the 3.3.0 milestone Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal Work made by Combodo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants