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

Can't obtain pessimistic lock when using findOne with where clause based on unique non-primary key #1291

Closed
mivanovaxway opened this issue Jan 11, 2021 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@mivanovaxway
Copy link

Describe the bug

I want to lock a row if it matches my search criteria.
(and also prevent such rows from being created while the lock is active).

id is my primary key.
sfdcId is not the primary key but a unique key(varchar).

My code:

let mainProductVersion = await em.findOne(Entities.SfdcProductVersions,
        {'sfdcId': artifactInput.metadata.sfdc_version_id},
        {lockMode: LockMode.PESSIMISTIC_READ});

Debug trace
select e0.* from sfdc_product_versions as e0 where e0.sfdc_id = 'f5DWWDqwDwd2411' limit 1

To Reproduce
Steps to reproduce the behavior:

  1. Use findOne with lockMode and query by non-primary key

Expected behavior
The query should contain a lock statement depending on the type of lock such as FOR UPDATE or lock in share mode.

Additional notes
I've tried locking the entity after it's returned, but that does not solve my issue - I want to make sure that
such an entity cannot be created in some other transaction. And since it does not exist at that point ->
I can't lock it.

Versions

Dependency Version
node 12
typescript 4.1.3
mikro-orm 4.3.4
mysql(server) 5.7
@B4nan B4nan added the bug Something isn't working label Jan 12, 2021
@B4nan B4nan closed this as completed in a0419a4 Jan 12, 2021
@mivanovaxway
Copy link
Author

mivanovaxway commented Jan 12, 2021

Update2:
Tested the fix and it works. Thanks.

Update:
@B4nan
I just saw the commit. Thanks a lot. Will test this and write back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants