-
Notifications
You must be signed in to change notification settings - Fork 223
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
Repeating query in django view that failed due to OperationalError (timeout) #2114
Comments
Thanks for reporting. I think this is expected given how the Django QuerySet works, they are lazy and evaluated only when used. Said that some special casing for the case may be possible if the QuerySet has not been already evaluated and there is a way to know it is not already cached? |
If the query to database was too heavy to be evaluated there is no way it was cached. You can only cache QuerySet that is computable (it's execution time fits in statement timeout). |
Exactly, so if we don't find it cached it means we should not evaluate it. |
Are you saying that there is some kind of safe-guard against evaluating non-cached QuerySets ? because i could not find such condition in library source code. This util function If it gives more context, the process of repeating SQL queries happens when |
No, I'm saying that it may be possible to add |
@xrmx what is the status of this issue ? Do you know if it will be corrected in near future ? |
@Pokapiec If you are going to open a PR I would gladly review it |
Describe the bug: When in django view some expensive query gets executed and it exceeds statement_timeout, OperationalError occurs and it makes repeatedly the same query X times (where X is probably the amount of stack traces pointing to code parts attached to
QuerySet
django class). Basically from what i've seen in the elasticapm codebase,elasticapm.utils.encoding.transform
function executesrepr
internal python func onQuerySet
class and under the hood, it refetches the whole query.In our project we use forked version of elastic-apm library with small change where we add info about current tenant to each transaction in celery.
To Reproduce
1ns
to simulateOperationalError
(SET LOCAL statement_timeout='1ns'
)Environment (please complete the following information)
Additional context
Add any other context about the problem here.
Click to expand
Click to expand
The text was updated successfully, but these errors were encountered: