question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Error] select_for_update cannot be used outside of a transaction.

See original GitHub issue

This 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:closed
  • Created 3 years ago
  • Comments:20 (20 by maintainers)

github_iconTop GitHub Comments

1reaction
edthrncommented, Jun 12, 2020

Fixed in release 1.2.2, tested and approved!

Thanks @maerteijn and @Koed00 💯

1reaction
maerteijncommented, May 13, 2020

I will do it this Friday, I didn’t forget 🙂

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found