N°9622 - Error in the user story life cycle#915
Conversation
|
| 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)
-
application/cmdbabstract.class.inc.php, line 3106-3110 (link)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 fromarray_keys().DBObject::Set()treats non-null linkset values as an object-set iterator and callsUpdateFromCompleteList($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
| if ($oAttDef->IsLinkSet()) { | ||
| $oObjectSet = $this->Get($sAttCode); | ||
| $oObjectSet->AddItem(MetaModel::GetObject($oAttDef->GetLinkedClass(), $aValues[0])); | ||
| $this->Set($sAttCode, $oObjectSet); |
There was a problem hiding this comment.
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.
| $this->Set($sAttCode, $aValues[0]); | ||
| if ($oAttDef->IsLinkSet()) { | ||
| $oObjectSet = $this->Get($sAttCode); | ||
| $oObjectSet->AddItem(MetaModel::GetObject($oAttDef->GetLinkedClass(), $aValues[0])); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?).
There was a problem hiding this comment.
If the attribute is a LinkSet, GetAllowedValues_att returns an ObjectSet from an OQL query. Therefore, I believe this object must exist.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
Internal