Skip to content

Commit

Permalink
allow one parameter to be omitted in txn
Browse files Browse the repository at this point in the history
  • Loading branch information
juliannguyen4 committed Nov 4, 2024
1 parent 3a72f43 commit ec5edbb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
2 changes: 1 addition & 1 deletion aerospike-client-c
22 changes: 11 additions & 11 deletions src/main/transaction/type.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,30 @@ static int AerospikeTransaction_init(AerospikeTransaction *self, PyObject *args,
goto error;
}

// Both reads and writes capacities must be specified,
// or both must be omitted
as_txn *txn;
if ((py_reads_capacity == NULL) ^ (py_writes_capacity == NULL)) {
PyErr_Format(PyExc_TypeError, "Both %s and %s must be specified",
kwlist[0], kwlist[1]);
goto error;
}
else if (py_reads_capacity && py_writes_capacity) {
uint32_t reads_capacity =
uint32_t reads_capacity, writes_capacity;
if (py_reads_capacity) {
reads_capacity =
get_uint32_t_from_pyobject(py_reads_capacity, kwlist[0]);
if (PyErr_Occurred()) {
goto error;
}
}
else {
reads_capacity = AS_TXN_READ_CAPACITY_DEFAULT;
}

if (py_writes_capacity) {
uint32_t writes_capacity =
get_uint32_t_from_pyobject(py_writes_capacity, kwlist[1]);
if (PyErr_Occurred()) {
goto error;
}
txn = as_txn_create_capacity(reads_capacity, writes_capacity);
}
else {
txn = as_txn_create();
writes_capacity = AS_TXN_WRITE_CAPACITY_DEFAULT;
}
txn = as_txn_create_capacity(reads_capacity, writes_capacity);

// If this transaction object was already initialized before, reinitialize it
if (self->txn) {
Expand Down
9 changes: 1 addition & 8 deletions test/new_tests/test_mrt_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ class TestMRTAPI:
{"reads_capacity": 256, "writes_capacity": 256, "invalid_arg": 1},
pytest.raises((TypeError)), "function takes at most 2 keyword arguments (3 given)"
),
(
{"reads_capacity": 256},
pytest.raises((TypeError)), "Both reads_capacity and writes_capacity must be specified"
),
(
{"writes_capacity": 256},
pytest.raises((TypeError)), "Both reads_capacity and writes_capacity must be specified"
),
(
{"reads_capacity": "256", "writes_capacity": 256},
pytest.raises((TypeError)), "reads_capacity must be an integer"
Expand Down Expand Up @@ -60,6 +52,7 @@ def test_transaction_class(self, kwargs: dict, context, err_msg: Optional[str]):
# Internal Python error thrown in Windows
assert str(excinfo.value) == "Python int too large to convert to C unsigned long"
else:
# Custom error thrown by Python client other platforms
assert str(excinfo.value) == err_msg

# Even though this is an unlikely use case, this should not cause problems.
Expand Down

0 comments on commit ec5edbb

Please sign in to comment.