-
Notifications
You must be signed in to change notification settings - Fork 42
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
docs: adds section about DB session management #124
docs: adds section about DB session management #124
Conversation
roksys
commented
Nov 18, 2019
- Closes docs: add reference about session management #123
docs/sessions_management.rst
Outdated
|
||
Transactions are tied to requests | ||
--------------------------------- | ||
In Invenio, a transaction is tied to a HTTP request. By default, the transaction is |
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.
In Invenio, a transaction is tied to a HTTP request. By default, the transaction is | |
In Invenio, a transaction is tied to an HTTP request. By default, the transaction is |
docs/sessions_management.rst
Outdated
on the records table when the database transaction isolation level is below repeatable read | ||
isolation level. | ||
|
||
When are SQL statements sent to the database server. |
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.
When are SQL statements sent to the database server. | |
When are SQL statements sent to the database server? |
docs/sessions_management.rst
Outdated
rolled back, and afterwards the entire transaction will be rolled back unless | ||
the exception is caught. | ||
|
||
For instance in the following code example, the entire transaction will be rolled backed: |
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.
For instance in the following code example, the entire transaction will be rolled backed: | |
For instance in the following code example, the entire transaction will be rolled back: |
docs/sessions_management.rst
Outdated
raise Exception() | ||
db.session.commit() | ||
|
||
On the other, in the following example, the propagation of the exception is stopped, |
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.
On the other.. what? On the other hand?
cb9ef84
to
caac649
Compare
docs/index.rst
Outdated
@@ -20,6 +20,7 @@ Invenio-DB. | |||
configuration | |||
usage | |||
alembic | |||
sessions_management |
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.
What about session_management
?
docs/sessions_management.rst
Outdated
In Invenio, a transaction is tied to an HTTP request. By default, the transaction is | ||
automatically rolled back unless you explicitly call ``db.session.commit()``. | ||
|
||
Exceptions causes rollback |
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.
I think it should be either "Exception causes rollback" or "Exceptions cause rollback".
docs/sessions_management.rst
Outdated
server when needed, or when explicitly requested via e.g. ``db.session.flush()`` or | ||
``db.session.commit()``. | ||
|
||
This means that in many cases, SQL insert and update statements are not sent to the |
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.
This means that in many cases, SQL insert and update statements are not sent to the | |
This means that in many cases, SQL INSERT and UPDATE statements are not sent to the |
docs/sessions_management.rst
Outdated
What about nested transactions? | ||
------------------------------- | ||
Nested transactions are using database save points, which allow you to do a partial | ||
rollback. Also, nested transactions causes a flush to the database, meaning that |
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.
rollback. Also, nested transactions causes a flush to the database, meaning that | |
rollback. Also, nested transactions cause a flush to the database, meaning that |
docs/sessions_management.rst
Outdated
db.session.commit() | ||
|
||
On the other hand, in the following example, the propagation of the exception is stopped, | ||
and only the db 2 operations are rolled back, while db operations 1 are committed to |
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.
and only the db 2 operations are rolled back, while db operations 1 are committed to | |
and only the db operations 2 are rolled back, while db operations 1 are committed to |
docs/sessions_management.rst
Outdated
def index(): | ||
# db operations 1 .... | ||
try: | ||
db.session.begin_nested(): |
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.
db.session.begin_nested(): | |
with db.session.begin_nested(): |
caac649
to
3e129aa
Compare
3e129aa
to
b3873a5
Compare