cap-js / cds-dbs

Monorepo for SQL Database Services for CAP
https://cap.cloud.sap/docs/
Apache License 2.0
35 stars 11 forks source link

@cap-js/postgres - some element names generate errors #177

Closed morseton closed 1 year ago

morseton commented 1 year ago

Description of erroneous behaviour

Hello, I've noticed that using some specific names on the elements of an entity will generate query errors. I will send an example of a simple project below, with two entities: image The entity Person will generate an error on the PG query whenever we expand to either "user" or "group". The other entity "PersonFixed" will not have the error, even when they are the same (the only difference being that the "user" and "group" associations have an underscore on their name).

Detailed steps to reproduce

  1. download: Sample.zip

  2. npm install

  3. npm run deploy

  4. npm start

  5. the following links will generate an error ($expand to user or group): http://localhost:4006/odata/v4/srv/Person?$expand=user http://localhost:4006/odata/v4/srv/Person?$expand=group

In the other hand, the following expands work (for entity PersonFixed): http://localhost:4006/odata/v4/srv/PersonFixed?$expand=_user http://localhost:4006/odata/v4/srv/PersonFixed?$expand=_group

This gives the impression that it's not possible to use "user" or "group" as an element name.

Details about your project

test
Node.js v18.16.1
@cap-js/postgres 1.0.1
@sap/cds 7.1.2
@sap/cds-compiler 4.1.2
@sap/cds-dk 7.1.1
@sap/cds-dk (global) 7.1.1
@sap/eslint-plugin-cds 2.6.3
@sap/cds-mtxs 1.10.0

Thanks in advance.

patricebender commented 1 year ago

GROUP is a reserved keyword, hence your query fails. @BobdenOs do we have a smart quoting mechanism in place which should escape the GROUP in this case?

BobdenOs commented 1 year ago

@patricebender here ?

patricebender commented 1 year ago

I have added some more reserved words in #178

patricebender commented 1 year ago

@morseton with the next @cap-js/postres release, the group identifier will be automatically quoted for you.

Thanks for reporting.

morseton commented 1 year ago

@patricebender Thanks for the quick fix. Will wait for the release.

patricebender commented 1 year ago

Closing this, fix available with the new version