Error with enum field type and custom conditional formatting

Hello

Feature(s) impacted

ENUM field

Observed behavior

  • ENUM field has the wrong type when updated

I have an ENUM field with a type: DataTypes.ENUM(-1, 0, 1, 2) let’s call it myEnum.
When a record is updated :
typeof record.myEnum is string if I update myEnum
typeof record.myEnum is number if I update an other field

  • ENUM field custom conditional formatting is not working

I have a custom conditionnal formatting on myEnum with altered values. The values are not altered so the conditional formatting is not working.

myEnum display settings :
Capture d’écran 2023-11-20 à 11.15.13

myEnum style in the records :
Capture d’écran 2023-11-20 à 11.16.18

Expected behavior

  • ENUM field should be a number in this case
  • ENUM display settings should be working with numbers

Context

  • Project name: MyCater
  • Team name: All
  • Environment name: all env => production/dev…
  • Agent (forest package) name & version: forest-express-sequelize@9.3.8
  • Database type: MySQL
  • Recent changes made on your end if any:
    The problem seems to come from the update of the package from
    forest-express-sequelize@8.4.7 to forest-express-sequelize@9.3.8

Hello @MarcoGarcia,

Thanks for your message :raised_hands:

I’ve just checked on my side with forest-express-sequelize@9, I was not able to reproduce your issue.
My enum field is well sent as a number when I update it (and it should not be sent if other fields are updated but not this one!) and the alter value feature is working well.

So we need to dig a bit more to found out where is your issue.
Could you please:

  • Tell me how you defined your enum field in your DB
  • Tell me what edit widget did you choose
  • Show me the payload that is sent when you say it’s sent as a string

Thanks!

Hello !

  • and it should not be sent if other fields are updated but not this one!
    => Yes I was checking in the beforeSave() hook of the model so I had every fields

  • Tell me how you defined your enum field in your DB
    => It’s a TINYINT(1) with a default value at 0

  • Tell me what edit widget did you choose
    => I chose dropdown with all values
    Capture d’écran 2023-11-20 à 15.36.15

  • Show me the payload that is sent when you say it’s sent as a string

This is the log of the payload and my record in the beforeSave hook (active and service are alike : dropdown, enum with number…) :

// Payload in routes/products.js
{
  data: {
    id: '63198',
    attributes: { active: '2' },
    type: 'products'
  }
}

// When I update service, log from models/products.beforeSave
products {
  dataValues: {
    id: 63198,
    service: '3',
    active: 2,
  },
  _previousDataValues: {
    id: 63198,
    service: 3,
    active: 2,
  },
  _changed: { service: true },
}

// When I update active, log from models/products.beforeSave
products {
  dataValues: {
    id: 63198,
    service: 3,
    active: '0',
  },
  _previousDataValues: {
    id: 63198,
    service: 3,
    active: 2,
  },
  _changed: { active: true },
}

@MarcoGarcia,

Judging from your widget edit settings, it seems that the Alter Data feature is working at least there!

When I asked you the payload that is sent when you say it’s sent as a string, I was thinking about inside your browser inside the network tab of the inspector.
Could you please share this? :pray:

And what do you do actually in the beforeSave hook?

Thanks a lot.

And what do you do actually in the beforeSave hook?

I check the active value, that’s how I found out the problem, but it’s after the log.

When I asked you the payload that is sent when you say it’s sent as a string, I was thinking about inside your browser inside the network tab of the inspector.

The request body inside the network tab is the same as in routes/products.js.

{"data":{"id":"63201","attributes":{"active":"2"}},"type":"products"}}
1 Like

@MarcoGarcia,

Thanks for your answer.

I’ve retried today, and strangely I was able to reproduce your problem.
It seems that we are not dealing well with this Enum of numbers.
Let me check why and if we can fix this.

In the meantime, I guess a workaround could be to define your field like this DataTypes.INTEGER. The alter values should work fine in the display widget settings, and you could use the dropdown you wanted in the edit widget (to limit what values could be entered).

Let me know.

Okay thanks,
For now I’ve made a fix where I check the active field like Number(active) so it’s ok

1 Like

@MarcoGarcia what’s strange here is that I tried on a project with typescript and it doesn’t even let me create this enum definition because it expects only strings on that function :thinking:

<string>(...values: string[]) => DataTypes.EnumDataType<string>

Hello @MarcoGarcia, do you still have this bug in your project ?

I’ve tried to reproduced it with Sequelize and MySQL without success,
in both cases (Creation & Update) I received a correct number as value in beforeSave hook of Sequelize.

Here is the exact configuration i’ve used

"meta": {
  "liana": "forest-express-sequelize",
  "liana_version": "9.3.8",
  "stack": {
    "database_type": "mysql",
    "engine": "nodejs",
    "engine_version": "18.14.0",
    "orm_version": "6.29.3"
  }
}

Have a nice day

1 Like

This will be consider as closed as we have no answer