[Error] select_for_update cannot be used outside of a transaction.
See original GitHub issueThis Django error (raised from SQL Compiler) pops up in my logs and prevent any scheduled tasks to run. The error is raised from this django_q line, which is very strange since the whole try
block is within the transaction.atomic()
context manager.
Any idea on why this is happening and how to fix it? Thanks!
Config:
- db: Postgres 11 with psycopg2 interface
- django-q 1.2.1
- django 3.0
- python 3.8
Edit
The error is reproduced in this basic demo app
Issue Analytics
- State:
- Created 3 years ago
- Comments:20 (20 by maintainers)
Top Results From Across the Web
Django select_for_update cannot be used outside of a ...
The answer is in the error, wrap the query in a transaction. Django's documentation is located here: ...
Read more >Why does .exists() respect .select_for_update() while . ...
I get an error select_for_update cannot be used outside of a transaction . I checked the queries that django made and they are...
Read more >Is there any risk in SELECT ... FOR UPDATE outside ...
A query is always in a transaction even if you don't start it explicitly. SELECT FOR UPDATE acquires an exclusive lock on rows...
Read more >ERROR: cannot execute SELECT FOR UPDATE in a read- ...
Hi, when I use lock! to lock a column for_update I got this error ... cannot execute SELECT FOR UPDATE in a read-only...
Read more >Django's select_for_update with Examples and Tests
The solution is to use select_for_update to take a database lock. ... which rely on having control over the outer transaction block.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Fixed in release 1.2.2, tested and approved!
Thanks @maerteijn and @Koed00 💯
I will do it this Friday, I didn’t forget 🙂