-
-
Notifications
You must be signed in to change notification settings - Fork 229
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
✨ add transaction types and api route helpers #3271
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
ab182b4
to
65b38ef
Compare
d5f32b3
to
7b24059
Compare
65b38ef
to
c6624e3
Compare
7b24059
to
bc1a121
Compare
// TODO: consider adding this and whitelisting all promises that don't need to be awaited with "void" | ||
// "@typescript-eslint/no-floating-promises": "error", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should do this once the whole stack is converted to knex. This will be a bit annoying because there are about 250 promises in our codebase that are not explicitly awaited, many of them totally fine (e.g. react event handlers that don't await the result of the handler); but now that we switch to transactions on all api router handlers, failing to await a promise could potentially try to access the database transaction after it has been commited or rolled back. Cases where this happens were an error before already (e.g. errors in these promises would not be reported back) and could be related to #3159 and other similar issues.
c6624e3
to
4e97262
Compare
bc1a121
to
631b03e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, hard work!
What I did as part of this review:
- Went over (pretty much) everything and checked that it makes rough sense
- For
apiRouter
in particular, checked that we never use a transaction with the wrong kind of permissions - As a sanity check, I made the RO and RW types incompatible to see all the places where a RW transaction is passed to a method requiring a RO transaction - and all of these places make sense, i.e. the caller actually writes something.
It would be great if we could somehow also remove the .insert
, .update
etc. methods from the RO transaction altogether, but I don't believe this to be possible given the query builder nature of knex. A man can dream...
4e97262
to
741775f
Compare
631b03e
to
12b9910
Compare
741775f
to
cb3f324
Compare
1688723
to
c24e522
Compare
cb3f324
to
ec8295d
Compare
c24e522
to
b53c7a5
Compare
ec8295d
to
3ac5f23
Compare
b53c7a5
to
2239d84
Compare
3ac5f23
to
410db2f
Compare
2239d84
to
a69e10f
Compare
410db2f
to
0224101
Compare
a69e10f
to
05c8deb
Compare
0224101
to
d45e80e
Compare
05c8deb
to
b603737
Compare
This PR adds custom types for read only transactions and read/write transactions. Through some typescript magic this is set up so that functions that need a read only transaction (because they only run
select
statements) can also be given read/write transactions but functions that need read/write transactions do not accept a readonly transaction.This PR also adds helper functions for API request handlers that also set up a transaction (which means that instead of writing a callback that takes a (request, response) tuple you write one that works with a (request, reqsponse, transaction) tuple).