Skip to content

updating an array with unshift does not work #11247

Closed

Description

@fareshan

What are you doing?

This issue happens after upgrading to sequelize v5.

In this example, product is a table and urls is a column of type DataType.ARRAY(DataType.STRING):
This does not work:

product.urls.unshift('some-string');
await product.save();

And this works:

const urls = product.urls;
urls.unshift('some-string');
product.urls = urls;
await product.save();

The issue is with changed fields detection in the model.js file.

Environment

Dialect:

  • mysql
  • postgres
  • sqlite
  • mssql
  • any
    Dialect pg version: 6.4.2
    Database version: 10
    Sequelize version: 5.10.3
    Node Version: 10.16.0
    OS: macos 10.14.5
    If TypeScript related: TypeScript version: 3.4.3
    Tested with latest release:
  • No
  • Yes, specify that version:

Activity

  1. papb commented on Jul 30, 2019

    @papb
    Member

    Tested with latest release: No

    Could you please test with the latest release, just in case?

  2. added
    dialect: postgres
    status: awaiting response
    type: bug
    on Jul 30, 2019
  3. fareshan commented on Jul 30, 2019

    @fareshan
    Author

    @papb I tested it with the latest release v5.12.0 and I got the same behavior

  4. added
    status: understood
    and removed
    status: awaiting response
    on Jul 30, 2019
  5. Sydneyisachampion1 commented on Jul 31, 2019

    @Sydneyisachampion1

    What is that

  6. github-actions commented on Nov 8, 2021

    @github-actions
    Contributor

    This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂

  7. self-assigned this
    on Jan 5, 2022
  8. ephys commented on Jan 5, 2022

    @ephys
    Member

    This is a know issue. Sequelize can't currently detect that change. You need to use Model#changed('urls', true) ; or ,as you did, reassign (product.urls = urls;).

    I don't consider it a bug but it's still something I'm looking into resolving as it pops up often.
    I've opened a discussion here #14300 regarding changing how we detect changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

dialect: postgresstatus: understoodtype: bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions