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

v6 sqlite upsert returns incorrect value for UUID values on subsequent upserts #12426

Open
2 of 7 tasks
EyePulp opened this issue Jun 25, 2020 · 3 comments
Open
2 of 7 tasks
Labels
Great SSCCE This issue has a great SSCCE/MCVE/reprex posted and therefore deserves extra attention! :) type: bug

Comments

@EyePulp
Copy link

EyePulp commented Jun 25, 2020

Issue Description

Under sequelize v6, when using sqlite for upserts and a UUID primary key, it seems like subsequent upserts with the same data are not returning the first instance UUID/pk value, and instead a returning a new UUID.

This appears to differ under postrgres, which under subsequent requests is returning the original pk/UUID.

What are you doing?

Here is the link to the SSCCE for this issue: sequelize/sequelize-sscce#87
Unfortunately v6 isn't available yet in that project, and attempting to update failed, so I was only able to test v6 locally for sqlite and v5 for postgres under the SSCCE repo.

Here's the heart of it

    const Foo = sequelize.define('Foo', {
        id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true },
        name: { type: DataTypes.STRING, allowNull: false, unique: true }
    });

    await sequelize.sync();
  
    // upsert the initial data, with a unique "name" 
    const [f1] = await Foo.upsert({ name: 'foo' }, { returning: true });
    expect(await Foo.count()).to.equal(1);
  
    // upsert the same data as before, which should result in matching the "name" 
    // and returning the original record & "id"    
    const [f2] = await Foo.upsert({ name: 'foo' }, { returning: true });
    expect(await Foo.count()).to.equal(1);
    expect(f1.id).to.equal(f2.id);

What do you expect to happen?

I expect f2 to be the same instance (or at least have the same values) as f1, as an upsert with returning: true should bring back the created/updated record.

What is actually happening?

The id values differ between subsequent runs.

// local test output v6.1.0 w/ sqlite
f1.id: 79355efc-68a1-4935-b97f-03b8f2012730
f2.id: 46279f95-f88c-4325-8c58-d0a1237824c1

Additional context

The second call isn't creating a new record in the database (the unique constraint is working), but the upsert result isn't bringing back the expected response.

Environment

  • Sequelize version: v6.1.0
  • Node.js version: v12.16.3X
  • Operating System: OSX & docker node:12-alpine

Issue Template Checklist

How does this problem relate to dialects?

  • I think this problem happens regardless of the dialect.
  • I think this problem happens only for the following dialect(s): sqlite
  • I don't know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I don't know how to start, I would need guidance.
  • No, I don't have the time, although I believe I could do it if I had the time...
  • No, I don't have the time and I wouldn't even know how to start.
@sushantdhiman sushantdhiman added type: bug Great SSCCE This issue has a great SSCCE/MCVE/reprex posted and therefore deserves extra attention! :) labels Jun 26, 2020
@github-actions
Copy link
Contributor

github-actions bot commented Nov 2, 2021

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. 🙂

@github-actions github-actions bot added the stale label Nov 2, 2021
@EyePulp
Copy link
Author

EyePulp commented Nov 2, 2021

Well, nuts.

@cirosantilli
Copy link

SQLite RETURNING was added in 2021 BTW: https://www.sqlite.org/lang_returning.html I think that might make this PR possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Great SSCCE This issue has a great SSCCE/MCVE/reprex posted and therefore deserves extra attention! :) type: bug
Projects
None yet
Development

No branches or pull requests

3 participants