Comments (3)
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 _executor.id
is indeed private. While adding a setter would be the easy way out of this, it would potentially allow users to write code like this:
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 x-arango-trx-id
setting trick is way better - it may look weird, but it's "loud and clear", there will be no problem figuring out what (and why) you wrote it there.
Following up on what I would consider a reasonable solution
- Modify the
TransactionAPIExecutor
constructor such that it contains a new field,transaction_id
, which can beNone
orstr
(basically anOptional[str]
). In case it is astr
, the constructor should no longer send a request to /_api/transaction/begin, but set the_id
property directly and check thestatus()
of the transaction in order to validate it really exists. - The same parameter should be added to the
TransactionDatabase
, which would forward it to the executor. This is straight forward. - The
StandardDatabase
should get afetch_transaction
method, which takes the transaction ID and returns aTransactionDatabase
. I'm suggestingfetch_transaction
because it implies that a transaction may (or may not) be there, rather than continuing one (which is not necessarily "paused").
Testing
Introduce a test case test_transaction.py
, something simple, just to check that we're able to use both the initial transaction and the "continued" object.
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
A small edit in transaction.rst would be great to showcase how fetch_transaction
is supposed to be used.
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.
from python-arango.
from python-arango.
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 TransactionInitError
and feeding it the response produced results that would be confusing to the end user. I also realized that perhaps checking the status of a transaction in an external system (that may be committed already) could be useful in some niche cases.
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.
from python-arango.
Related Issues (20)
- Documentation issue: ordered/geoJSON on collection.add_geo_index HOT 1
- Authenticate using User JWT-Token HOT 1
- Custom JSON serializer not being used for bulk operations HOT 3
- Edges not retrievable without committing transaction HOT 2
- python-arango is not working without pip-install installation HOT 3
- Content in API docs of branch `main` disappeared HOT 1
- merge functionality HOT 1
- Replacement for `pkg_resources` HOT 1
- Transactions Failing on Collection Deletion HOT 3
- Unable to disable request timeout HOT 2
- Requests with endpoint="/_api/simple/..." fail HOT 10
- API Specification Page is not rendering
- Collection.find does not work in 7.6.1 if filter attribute is set to none HOT 3
- Enum can't be serialized anymore after upgrade to 7.6.2 HOT 2
- bind_vars type hints are incomplete HOT 4
- broken build_filter_conditions for keys with spaces // backtick escaping missing? HOT 2
- Unix socket support HOT 5
- Make ArangoClient generic to support typing when a custom serialiser is used HOT 9
- `arango.exceptions.GraphTraverseError: [HTTP 404][ERR 404] unknown path '/_api/traversal'` when using `traverse` (arangodb 3.12) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-arango.