Hello all,
In our API, we have a function that at a certain point lists each repitem in a given fieldset, and sends a button in the chat for each. The list creation goes like below. (Note that SPM is a code we have in repitems name for easier identification of the fieldset it is pertaining to, and for each repitem, we have a _RowID attribute that copies the unvandalized rowID)
_.each( attributes, function ( indexAttributes ) {
if( indexAttributes.get( "name" ).endsWith( "_SPM_RowID" )) {
let row = indexAttributes.get( "current" );
if ( Earthdawn.getAttrBN( po.charID, Earthdawn.buildPre( "SPM", row ) + "Rank", 0, true) >= circle) // Only list the matrices of a rank ot hold this spell.
matrices.push( row );
log("Matrix search attribute name " + indexAttributes.get( "name" ) + " & value " + row);
}
}); // End for each attribute.
log("found matrixes quantity " + matrices.length);
For reasons I don't understand, this code sometimes generate duplicates, (i.e. the same entry is listed twice). Of course a simple safeguard in the if will get rid of this duplicate
&& !matrices.includes(row)
But I am now worried about the root cause of these duplicates as it could also happen in other areas of the code.
See below a log generated by this function on a test character that has 2 elligible repitems
"Matrix search attribute name repeating_matrix_-MsXsyjPtRdTxSmBZGqA_SPM_RowID & value -MsXsyjPtRdTxSmBZGqA"
"Matrix search attribute name repeating_matrix_-MsXsyjPtRdTxSmBZGqA_SPM_RowID & value -MsXsyjPtRdTxSmBZGqA"
"Matrix search attribute name repeating_matrix_-MsY0FkS5DRxkZvEnwoJ_SPM_RowID & value -MsY0FkS5DRxkZvEnwoJ"
"Matrix search attribute name repeating_matrix_-MsXsyjPtRdTxSmBZGqA_SPM_RowID & value -MsXsyjPtRdTxSmBZGqA"
"Matrix search attribute name repeating_matrix_-MsY0FkS5DRxkZvEnwoJ_SPM_RowID & value -MsY0FkS5DRxkZvEnwoJ"
"found matrixes quantity 5 »
It can clearly be seen that the repitem with rowID ending in Gga comes three times, while the woJ comes 2 times, when it would be expected that they come only once...
I was playing with 2 hypothesis:
1- Can it be a bug from the _.each function that could come several time at a same entry
2- Could it be that in the "database of all attributes" there are duplicates, where the attribute repeating_matrix_-MsXsyjPtRdTxSmBZGqA_SPM_RowID is duplicated, with the same name and same value... Maybe at some point when trying to write on this attribute instead of overwriting, it just duplicated it...
so I added a log of JSON.stringify(indexAttribute)
"indexAttribute {\"name\":\"repeating_matrix_-MsXsyjPtRdTxSmBZGqA_SPM_RowID\",\"current\":\"-MsXsyjPtRdTxSmBZGqA\",\"max\":\"\",\"_id\":\"-MsXsyjnfCDN7Jgew3n_\",\"_type\":\"attribute\",\"_characterid\":\"-MKPtPDNw5d-Rby1qw3U\"}"
"indexAttribute {\"name\":\"repeating_matrix_-MsXsyjPtRdTxSmBZGqA_SPM_RowID\",\"current\":\"-MsXsyjPtRdTxSmBZGqA\",\"max\":\"\",\"_id\":\"-MsXsytw5KsJY3Bryrq_\",\"_type\":\"attribute\",\"_characterid\":\"-MKPtPDNw5d-Rby1qw3U\"}"
So there is clearly 2 attributes, with different _id, but the same name !?!
I have to dig in my code to understand how this could happen, but this is worrying for me as it means:
1- I don't know what happens when you try to read/write such a duplicate... Can they actually hold 2 different values ??
2- It is potentially now in my released code, so even if I find and fix the part that creates the duplicate, there are campaigns out there that have these duplicates...
Is it a known issue that you can have several attributes with same name but different _id ? Any recommandation?