-
Notifications
You must be signed in to change notification settings - Fork 76
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
feature request: Continue an existing transaction #329
Comments
Hi @Moortiii, I understand your proposal, and I think it is quite sensible. Updating the same transaction concurrently can cause some uncertainty due to timing issues, but when done carefully, I can imagine some valid use-cases. As you pointed out, the trx = db.begin_transaction()
col1 = trx.collection("col1")
trx._executor._id = another_transaction
col2 = trx.collection("col2") Not only the transaction ID can easily get lost, thus preventing one from ever accessing the initial transaction again, but the problem can be easily overlooked, as it is hidden in just one line of code. Frankly, I believe even the Following up on what I would consider a reasonable solution
Testing def test_transaction_fetch(db, col, docs):
txn_db = db.begin_transaction(write=col.name)
txn_col = txn_db.collection(col.name)
txn_db2 = db.fetch_transaction(txn_db.transaction_id)
# insert some documents using both txn's
# ... Docs I'm ready to implement the above. Or, if you want to give it a go, I'm perfectly fine with that, but don't feel pressured, I'm just mentioning since you offered. Let me know how you want to proceed. |
These seem like sensible changes that should be straight forward enough to implement. I'll give it a shot later today and report back. Thanks!
I agree with your comment about `continue` which could imply the ability to "pause" a transaction. I hadn't thought about it that way, but you're probably right that it would cause some confusion, especially for new users of ArangoDB.
|
I've opened a PR @apetenchea. I did consider something like this as well: request = Request(
method="get",
endpoint=f"/_api/transaction/{transaction_id}",
)
resp = self._conn.send_request(request)
if not resp.is_success:
raise TransactionInitError(resp, request)
result = resp.body["result"]
if result["status"] != "running":
raise TransactionInitError(resp, request)
self._id = transaction_id My intention was to prevent a user from 'continuing' a transaction that is already committed or aborted, which would be mostly pointless. However, since the response from the API when fetching the status is 200 OK, raising a As a sidenote, I noticed that the docs on contributing that are present in the sphinx documentation appears to be outdated. I had to follow the contribution guidelines directly in the repository to get anywhere. |
I've come across a case where a transaction needs to be shared across multiple systems. If we wrap the REST API we can easily achieve this by setting the
x-arango-trx-id
header. However, we would like to be able receive transaction IDs on both ends and continue the transaction seamlessly using the python-arango interface, instead of crudely performing raw queries against/_cursor
.I've come up with the following hack, which does work, but given that
_executor
is private, and_executor.id
specifically doesn't have a setter, I'm guessing there may be a reason it's discouraged:Would it make sense to support something like this directly? It seems to me like a reasonable use-case. If so, I'm happy to take a stab at developing a PR for this myself.
The text was updated successfully, but these errors were encountered: