Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot edit record on model with two primary keys #210

Open
dynamiccast opened this issue Sep 25, 2018 · 4 comments
Open

Cannot edit record on model with two primary keys #210

dynamiccast opened this issue Sep 25, 2018 · 4 comments
Labels

Comments

@dynamiccast
Copy link

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
@arnaudbesnier
Copy link
Member

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.

@totolouis
Copy link

totolouis commented Sep 17, 2020

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.

@killix
Copy link

killix commented May 27, 2021

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 :)

@arnaudbesnier
Copy link
Member

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, ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants