-
Notifications
You must be signed in to change notification settings - Fork 91
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 support for SELECT FOR UPDATE #1065
Conversation
@dkopitsa Can you please run locally . |
6296078
to
fdd7f53
Compare
Done. Sorry about the linters; I wanted to fix the tests quickly and used GitHub's web editor. |
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #1065 +/- ##
==========================================
- Coverage 92.66% 88.47% -4.20%
==========================================
Files 115 116 +1
Lines 8444 8543 +99
==========================================
- Hits 7825 7558 -267
- Misses 619 985 +366 ☔ View full report in Codecov by Sentry. |
No worries. Thanks for your PR. Looks good to me, but you'll have to wait for @dantownsend proper review. |
0d0cb80
to
5e3c4f0
Compare
Any updates here? |
Hi @dantownsend , could you please review the PR? If there's anything that needs further work or adjustments, let me know, and I'll make the necessary changes |
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.
Hi - sorry for the delay with this. I think the PR was opened while I was busy adding MFA to Piccolo Admin.
It looks really good, but my main concern is whether we should refactor it slightly, so instead of the method being for_update
, instead it should be something like this:
await Band.select().locking('for update')
Or even:
await Band.select().for('update')
Just because there are multiple strengths of locks:
https://www.postgresql.org/docs/current/sql-select.html#SQL-FOR-UPDATE-SHARE
We could support them all in one method, rather than having to add more methods in the future for each one.
I quite like the idea of calling the method for
but it clashes with the Python for
keyword, which can sometimes cause weird bugs. So lock_for
might be better.
What do you think?
@@ -0,0 +1,62 @@ | |||
.. _limit: |
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.
We should get rid of this.
Good point. Personally, I don't use anything other than 'update', but it could be useful, especially for the ORM. await Band.select().lock_for('update', skip_locked=True) looks good to me. I'll make the necessary changes. |
I fixed the formatting in test_select.py, please run workflow again. |
@dkopitsa This looks great - thanks a lot! I'll test it out locally. |
@dkopitsa I've merged this in now, via another branch. I just changed the method name from await Band.select().lock_for() So now it's this instead: await Band.select().lock_rows() Thanks a lot for all the effort you put into this - it's a very nice feature to have 👍 |
Add clause
for_update(nowait: bool = False, skip_locked: bool = False, of=())
forobjects
andselect
query.Similar to django's select_for_update
Closes #932
Example usage:
Get one row matching the status, locks it for update, and skips any already locked rows.
Ensure that the selected object is locked and cannot be modified by other transactions