Skip to content

Commit d04fc7f

Browse files
authored
Fixup a bug in the sync polling exec function (#29)
In the case where the response had to poll, there was a silly mistake where we were reading the wrong field off the response. Previously: ```julia julia> RAI.exec(ctx, "nhd-test-1", "nhd-s", """ 2 + 2 * 2, "hi", 'a' """) ERROR: KeyError: key "id" not found Stacktrace: [1] getindex(h::Dict{String, JSON3.Object{Vector{UInt8}, Vector{UInt64}}}, key::String) @ Base ./dict.jl:481 [2] exec(ctx::Context, database::String, engine::String, source::String; inputs::Nothing, readonly::Bool, kw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) @ RAI ~/work/rai-sdk-julia/src/api.jl:403 ``` This is now fixed: ```julia julia> RAI.exec(ctx, "nhd-test-1", "nhd-s", """ 2 + 2 * 2, "hi", 'a', "hello", '2', 2.0 """) Dict{String, Any} with 4 entries: "metadata" => JSON3.Object[{… "problems" => Union{}[] "results" => Pair{String, Arrow.Table}["/:output/Int64/String/… "transaction" => {… ```
1 parent aa7a1ec commit d04fc7f

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/api.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,13 +400,13 @@ function exec(ctx::Context, database::AbstractString, engine::AbstractString, so
400400
for duration in backoff
401401
transaction_is_done(txn) && break
402402

403-
txn = get_transaction(ctx, txn["id"])
403+
txn = get_transaction(ctx, transaction_id(txn))
404404
sleep(duration)
405405
end
406406
if haskey(txn, "results")
407407
return txn
408408
else
409-
id = txn["id"]
409+
id = transaction_id(txn)
410410
t = @spawn get_transaction(ctx, id)
411411
m = @spawn get_transaction_metadata(ctx, id)
412412
p = @spawn get_transaction_problems(ctx, id)
@@ -419,9 +419,10 @@ function exec(ctx::Context, database::AbstractString, engine::AbstractString, so
419419
)
420420
end
421421
catch
422+
@info "TXN" txn
422423
# Always print out the transaction id so that users can still get the txn ID even
423424
# if there's an error during polling (such as an InterruptException).
424-
@info """Exception while polling for transaction:\n"id": $(repr(txn["id"]))"""
425+
#@info """Exception while polling for transaction:\n"id": $(repr(transaction_id(txn)))"""
425426
rethrow()
426427
end
427428
end
@@ -474,6 +475,13 @@ function transaction_is_done(txn)
474475
return txn["state"] ("COMPLETED", "ABORTED")
475476
end
476477

478+
function transaction_id(txn)
479+
if haskey(txn, "transaction")
480+
txn = txn["transaction"]
481+
end
482+
return txn["id"]
483+
end
484+
477485
function get_transaction_metadata(ctx::Context, id::AbstractString; kw...)
478486
path = PATH_ASYNC_TRANSACTIONS * "/$id/metadata"
479487
rsp = _get(ctx, path; kw...)

0 commit comments

Comments
 (0)