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

fix: don't overwrite primaryKey with LAST_INSERT_ID() if exists #398

Merged
merged 2 commits into from
Aug 31, 2023

Conversation

cyjake
Copy link
Owner

@cyjake cyjake commented Aug 31, 2023

att

@JimmyDaddy JimmyDaddy merged commit 1ec493f into master Aug 31, 2023
4 checks passed
@JimmyDaddy JimmyDaddy deleted the fix-oceanbase-insert-id branch August 31, 2023 02:40
@@ -806,7 +806,8 @@ class Bone {

const spell = new Spell(Model, opts).$insert(data);
return spell.later(result => {
this[primaryKey] = result.insertId;
// LAST_INSERT_ID() breaks on TDDL, and on OceanBase if primary key is not integer
if (this[primaryKey] == null) this[primaryKey] = result.insertId;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没测试用例么。。

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

要 oceanbase 用非整型字段当主键才可以复现,比较难复刻……

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

刚好带来一个单测报错
image

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

厉害👍

这个是数据库自动做了取整然后通过 L809 订正了 user.id?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MySQL 本地测试,数据库存的肯定不是这个浮点数 ID,否则不会报错(后面查用户权限的时候失败)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

理论上 user_id 如果声明了类型,也可以在应用层取整缓解这个问题

主要这个 edge case 和之前 ob 那个是冲突的,ob 那个是主键自定义之后返回了一个其他的唯一 id(可能是内部 id),只能两者里面选一个……

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

Successfully merging this pull request may close these issues.

4 participants