Forest new agent - collection showing wrong value

Feature(s) impacted

show records of collection

Observed behavior

records listed on Forest:


corespondant in BD is the View “combined_users_connections”

Expected behavior

Expected to have the same lines as in the view on DB:

  • Project name: clevermate v2
  • Environment name: dev
  • Agent technology: (nodejs,
  • Agent (forest package) name & version: 1.58.3
  • Database type: postgres
  • Recent changes made on your end if any: …

Hello,

Could you show the response of the GET call in the network tab (with the values spread out so we can see if they are indeed identical) ?
Is there any specific customization on this table, do you observe the same behaviour on any other collection ?

Hi @dogan.ay

This is the network log for the GET :


the api response looks good for the data (child_name, match_id,…) how ever the collection in the left: “Matches” shows different values.
The customization for this collection: only addFields and Actions.
I got the issue only with this collection.

I would bet that the issue comes from the identical ids of your 3 records, as shown in the network response.

Could you share the definition of your table ? does it have a PK constraint ?

Actually the collection is a View in DB (it doesnt have a PK) but the match_id here is the unique key, in the network response it is correct in both 3 rows.


agent.customizeCollection("combined_users_connections", collection => {

  setFieldEnums(collection, 'action_a_mener', ['Date Essai ?', 'Feedback Essai ?', 'Transformer (l\'essai)', 'Décrochage', 'Trouver solution', '']);
  setFieldEnums(collection, 'status', ['Actif', 'Archivé']);

  collection.addManyToOneRelation("pr", "c_user_program_r", {foreignKey:"pr_id", foreignKeyTarget:"id"})
  collection.addField("tuteeRef", {...}
// other Fields

collection.addAction("Envoyer mail tutor", {
    scope: "Single",
// ...
// other Actions
export function setFieldEnums(collection, field, enumValues) {
  const OPERATORS = ['Present',
    'Blank',
    'Missing',
    'Equal',
    'NotEqual',
//..
    ]
  collection.addField(field + '_enum', {
    columnType: 'Enum',
    enumValues: enumValues,
    dependencies: [field],
    getValues(records) {
      return records.map(record => record[field]);
    },
  })
    .removeField(field)
    .replaceFieldWriting(field + '_enum', async value => {
      return { [field]: value };
    });

  OPERATORS.forEach(operator => {
    collection.replaceFieldOperator(field + '_enum', operator, async (value, context) => {
      return {
        field, operator, value
      }
    });
  });
  

}

Could you share the SQL definition of your View ? You can send it to me privately if you wish to not make it public

After looking at the code, to fix this issue, the easiest way would be for you to duplicate your unique field inside your view (here match_id) and rename it simply as id.

As postgresql views do not support constraints, even if the view is a wrapper of a table, the agent will not be able to accurately identify primary keys. At the current time we have a function that tries to guess which columns are primary keys, renaming a field to id will make the function use this column as a PK.