Comments (7)
Okay, figured out this bug. We've cut a release of v1.10.0 which fixes this error. Thanks for the report, your reproduction repo was really helpful in debugging it!
from database-js.
Hey there @jacobwgillespie and @OultimoCoder . We've put this on the radar and hope to get around to patching it ASAP. Thank you for opening this ticket and making a repo with a reproduction, it's greatly appreciated.
from database-js.
Upgraded the package in all my repos that use this and tests all pass (had tests failing due to this error before). Thank you!
from database-js.
On ^, the minimal subset of the reproduction code at https://github.com/jacobwgillespie/kysely-planetscale-issue-20 is this:
const conn = connect(config.database)
try {
await conn.transaction(async (trx) => {
const userId = await trx.execute(
'insert into `user` (`name`, `email`, `is_email_verified`, `password`, `role`) values (?, ?, ?, ?, ?)',
[name, email, true, null, 'user']
)
await trx.execute(
'insert into `authorisations` (`user_id`, `provider_type`, `provider_user_id`) values (?, ?, ?)',
[Number(userId.insertId), providerType, providerUserId]
)
return userId
})
} catch (error) {
await conn.execute('delete from `user` where `user`.`email` = ?', [email])
throw new Error('User already exists!')
}
The first insert into 'user'
fails as it's a duplicate of an existing row's email
value - this throws an error, but then the delete from 'user'
in the catch block is stuck on a lock.
from database-js.
@jacobwgillespie just out of curiosity if you don't mind, inside of the catch
block, if you do await conn.execute("rollback")
does that allow things to continue correctly?
In theory we should be doing it here automatically https://github.com/planetscale/database-js/blob/main/src/index.ts#L189
Just not 100% sure without digging in why that wouldn't be working.
from database-js.
@mattrobenolt Adding await conn.execute('ROLLBACK')
did not free the lock — the rollback returns without an error, but then the delete from 'user'
still times out due to the lock.
from database-js.
I also tried just issuing the transaction commands directly, since I know transaction()
is creating a second connection, and that also fails with the lock timeout:
try {
await conn.execute('BEGIN')
const userId = await conn.execute(
'insert into `user` (`name`, `email`, `is_email_verified`, `password`, `role`) values (?, ?, ?, ?, ?)',
[name, email, true, null, 'user']
)
await conn.execute('COMMIT')
} catch (error) {
await conn.execute('ROLLBACK')
await conn.execute('delete from `user` where `user`.`email` = ?', [email])
throw new Error('User already exists!')
}
from database-js.
Related Issues (20)
- Strongly type "type" property of Field
- Type error fetch failed HOT 10
- Automatically handle seeing a port 3306 in a connection string HOT 4
- INVISIBLE columns showing up with SELECT * HOT 6
- feat: Support syntax helper for "bulk insert with parameters"
- Malformed interface Field HOT 1
- [Feature] A type can be defined for `rows` in the query result HOT 6
- json_object converts bigints to numbers HOT 2
- Weird error with FKC HOT 5
- Error: direct DDL is disabled. Shadow Databases not helping, Development Branches not helping HOT 4
- New tables not found in foreign key enabled cluster HOT 2
- bug: `BLOB` / `Buffer` input parameters result in corrupted data
- Simple `show tables` statement not cast correctly by default HOT 11
- UUIDs Get Returned Incorrectly HOT 2
- CF Hyperdrive support? HOT 5
- Bug with JSON columns on >=1.15.0 HOT 12
- Customising cast results in unexpected behaviour HOT 2
- Numbers returned as strings HOT 15
- CI for tagging and pushing releases
- VT12001: unsupported: subqueries in DML when using delete() with where that filters on relation field HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from database-js.