Invalid projection for custom foreign keys

Hello!

I am facing an issue when loading some table (collection) from one of our MariaDB database. The targeted table has custom relation (check screenshot bellow) that seem to prevent the agent to do the proper projection.
Once the foreign key constraints are removed, the collection can load properly.

Thanks!

Feature(s) impacted

Loading collection

Observed behavior

Loading collection related to a MariaDB table fails due to custom relation (cf image below).

Expected behavior

The collection loads successfully.

Failure Logs

===== An exception was raised =====
GET /patient?{
 timezone: Europe/Paris,
 fields[health_insurance_fund]: name,
 fields[identity]: id,
 fields[patient]: address,address_2,application_id,birthdate,birthname,city,civility,country,created_date,created_from,deactivated_dtm,email,firstname,gender,health_insurance_fund,icd_codes,identity,inactive,inactive_dtm,inclusion_dtm,ipp,lastname,long_term_condition,middle_name,nir,person_to_notify,phone_numbers,referring_cardiologist_id,referring_physician_id,research_consent,rhythmologist,routine_care_consent,source,state,updated_date,vendor_id,zip_code,
 fields[rhythmologist]: identity,
 page[number]: 1,
 page[size]: 15
}

 Invalid projection 

Error: Invalid projection
    at Function.parseProjection (/Users/juliensarazin/workspace/implicity-healthcare/shared/nest-admin/node_modules/@forestadmin/agent/src/agent/utils/query-string.ts:62:13)
    at Function.parseProjectionWithPks (/Users/juliensarazin/workspace/implicity-healthcare/shared/nest-admin/node_modules/@forestadmin/agent/src/agent/utils/query-string.ts:67:42)
    at ListRoute.handleList (/Users/juliensarazin/workspace/implicity-healthcare/shared/nest-admin/node_modules/@forestadmin/agent/src/agent/routes/access/list.ts:22:25)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at ErrorHandling.errorHandler (/Users/juliensarazin/workspace/implicity-healthcare/shared/nest-admin/node_modules/@forestadmin/agent/src/agent/routes/system/error-handling.ts:21:7)
    at Logger.logger (/Users/juliensarazin/workspace/implicity-healthcare/shared/nest-admin/node_modules/@forestadmin/agent/src/agent/routes/system/logger.ts:20:7)
    at bodyParser (/Users/juliensarazin/workspace/implicity-healthcare/shared/nest-admin/node_modules/koa-bodyparser/index.js:95:5)
    at cors (/Users/juliensarazin/workspace/implicity-healthcare/shared/nest-admin/node_modules/@koa/cors/index.js:110:16)
===================================

info: [200] GET /patient/count - 23ms

Context

  • Project name: mpcty-admin
  • Team name: operator
  • Environment name: Development
  • Agent type & version: @forestadmin/agent": "^1.0.0-beta.60",
  • Recent changes made on your end if any: None

Hello thank you for the report.
What do you mean by “custom relation” ? You create these relations with the .addOneToManyRelation for example ?
Thanks.

By custom I mean the primary key of one table is actually a foreign key of another one.
Table B.id 1:1 Table A.id
Table C.id 1:1 Table A.id
Table B.c_id N:1 Table C.id

I use the raw SqlDatasource:

        this.agent.addDataSource(
            createSqlDataSource(configuration.databaseURI),
        );

I can reproduce the bug. I will create a bug ticket to fix your problem as soon as possible.
Really thanks for your report :pray:

2 Likes

Hello,
We have merged a patch last week. :partying_face: Please update your agent to the latest version :pray:
tell me if you still have the bug :slight_smile:

1 Like