forest-express-sequelize icon indicating copy to clipboard operation
forest-express-sequelize copied to clipboard

Cannot edit record on model with two primary keys

Open dynamiccast opened this issue 7 years ago • 4 comments

Expected behavior

Forest should be able to update records even if model has multiple primary keys.

Actual behavior

On models with multiple primary keys, updates requests are wrongly crafted. The id field (my first PK) appears as a concatenation of my two PK in Forest. This id field is expected to be a uuid format and feeding the concatenation triggers an error in sequelize.

Failure Logs

[forest] 🌳🌳🌳  Unexpected error: invalid input syntax for type uuid: "9ed9c7e0-463a-465b-a147-3220380a7702-PHOTON-DEV1"                                                                        
SequelizeDatabaseError: invalid input syntax for type uuid: "9ed9c7e0-463a-465b-a147-3220380a7702-PHOTON-DEV1"                                                                                   
    at Query.formatError (/opt/node_modules/sequelize/lib/dialects/postgres/query.js:363:16)                                                                                                    
    at query.catch.err (/opt/node_modules/sequelize/lib/dialects/postgres/query.js:86:18)                                                                                                       
    at tryCatcher (/opt/node_modules/bluebird/js/release/util.js:16:23)                                                                                                                         
    at Promise._settlePromiseFromHandler (/opt/node_modules/bluebird/js/release/promise.js:512:31)                                                                                              
    at Promise._settlePromise (/opt/node_modules/bluebird/js/release/promise.js:569:18)                                                                                                         
    at Promise._settlePromise0 (/opt/node_modules/bluebird/js/release/promise.js:614:10)                                                                                                        
    at Promise._settlePromises (/opt/node_modules/bluebird/js/release/promise.js:689:18)                                                                                                        
    at Async._drainQueue (/opt/node_modules/bluebird/js/release/async.js:133:16)                                                                                                                
    at Async._drainQueues (/opt/node_modules/bluebird/js/release/async.js:143:10)                                                                                                               
    at Immediate.Async.drainQueues [as _onImmediate] (/opt/node_modules/bluebird/js/release/async.js:17:14)                                                                                     
    at runCallback (timers.js:763:18)                                                                                                                                                           
    at tryOnImmediate (timers.js:734:5)                                                                                                                                                         
    at processImmediate (timers.js:716:5)  

Context

Here is my model:

sequelize.define('Machine', {
  id: {
    type: DataTypes.UUID,
    defaultValue: DataTypes.UUIDV4,
    primaryKey: true,
  },
  name: {
    type: DataTypes.STRING,
    allowNull: false,
    primaryKey: true,
  },
  status: {
    type: DataTypes.STRING,
    allowNull: false,
  },
})

The id field is shown as a concatenation of id and name (my two primary keys) in Forest:

screen shot 2018-09-25 at 2 10 20 pm

  • Package Version: 2.16.0
  • Express Version: 4.16.3
  • Sequelize Version: 4.38.0"
  • Database Dialect: postgres
  • Database Version: 10.4

dynamiccast avatar Sep 25 '18 20:09 dynamiccast

Hi @dynamiccast,

Nice to see you there ;). Thank you for the feedback.

Composite primary keys is something Forest is supposed to handle well, but your issue shows that I am wrong...

We'll try to prioritise this fix.

arnaudbesnier avatar Oct 21 '18 22:10 arnaudbesnier

Hi ForestAdmin team!

How this issue is going? I still have issues when dealing with 2 primary keys.

-- EDIT

There is a work around. If you create a identity field on the table with 2 pk (I called it 'id_forest_admin') and change the pk of the model to be the new key, it is working.

totolouis avatar Sep 17 '20 02:09 totolouis

Hi ForestAdmin team,

We also experiment with this issue with our models with 2 Primary keys but with different behaviour. We got "href":"/forest/<entity>/undefined/relationships/<entity>" in the HTTP call response and the UI return the message

Cannot reach your data
Your server may be down or your database connection broken.
Please check your server logs for more information. If the error persists, please let us know.

Do you have an ETA for a fix? Since 2018 I think it's time now :)

killix avatar May 27 '21 19:05 killix

Hi @killix, The error message you have does not look like the one of the initial thread Can you create a topic with a very detailed description of your issue (model definition, admin backend error logs, page you ar navigating to...) in our Community Forum, ?

arnaudbesnier avatar May 28 '21 06:05 arnaudbesnier