-
-
Notifications
You must be signed in to change notification settings - Fork 31k
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
gh-129346: Handle allocation errors for SQLite aggregate context #129347
gh-129346: Handle allocation errors for SQLite aggregate context #129347
Conversation
@serhiy-storchaka I would not bother with backporting this. It is not a bug. |
I'll let this sit until tomorrow before landing (unless Serhiy gives a thumbs up before that time). |
I think that there is a bug. The first call of https://www.sqlite.org/c3ref/aggregate_context.html
If we can determine what the call was first, we can raise MemoryError for the first call and RuntimeError for the subsequent calls. Otherwise we should always raise MemoryError, it is simpler and safer. |
I'll go through this again; will ping you later Serhiy. |
The step callback is almost always the first, unless in some special circumstances where we'll go straight to the final callback (we've got a least one test case for this for aggregate functions in the test suite). I think your suggestion makes sense, Serhiy. |
IIRC, the only subsequent callback will be the final callback if the first step callback fails. |
if (aggregate_instance == NULL) { | ||
(void)PyErr_NoMemory(); | ||
set_sqlite_error(context, "unable to allocate SQLite aggregate context"); | ||
goto 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.
If we had a way to hook into the SQLite memory allocator, we could simulate out-of-memory, but unfortunately the sqlite3
extension module does not support this (yet).
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.
Should not we add checks also after other calls? Just for the case.
The query will be aborted if we set an SQLite error in step. We will go straight to final in that case; there will be no subsequent step callback (nor value nor inverse). |
Quoting the example code the SQLite docs for the inverse callback:
The comment from the value callback is not as explicit, though. |
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.
There are four calls of sqlite3_aggregate_context()
. One (in final_callback
) is checked for NULL. Two (in inverse_callback
and value_callback
) have asserts. Can we guarantee that they never fail?
It is my understanding that the value and inverse callbacks will not be invoked after a failed step callback. I think it would be a breaking change if SQLite changed this behaviour. I think the |
I worry about the case when |
final can be called for the case where no rows was returned by the SQL query. If no rows was returned, the value and inverse callbacks has no meaning at all. |
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.
Then LGTM.
This comment has been minimized.
This comment has been minimized.
pythonGH-129347) (cherry picked from commit 379ab85) Co-authored-by: Erlend E. Aasland <[email protected]>
GH-129372 is a backport of this pull request to the 3.13 branch. |
pythonGH-129347) (cherry picked from commit 379ab85) Co-authored-by: Erlend E. Aasland <[email protected]>
GH-129373 is a backport of this pull request to the 3.12 branch. |
…xt (GH-129347) (#129373) (cherry picked from commit 379ab85) Co-authored-by: Erlend E. Aasland <[email protected]>
…xt (GH-129347) (#129372) (cherry picked from commit 379ab85) Co-authored-by: Erlend E. Aasland <[email protected]>
connection.c
#129346