Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/batchimages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function _batchimages_legacy(auth::Authentication)
r = _restcall(auth, :GET, "juliaruncloud", "get_image_options")
if r.status == 200
try
json = JSON.parse(String(r.body))
json = JSON.parse(String(r.body); dicttype=Dict)
if json["success"] && haskey(json, "image_options")
image_options = json["image_options"]
default_options = [
Expand Down
2 changes: 1 addition & 1 deletion src/jobs/jobs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ struct Job
Dict{String, Any}() # TODO: drop Nothing?
else
try
JSON.parse(unescape_string(inputs))
JSON.parse(unescape_string(inputs); dicttype=Dict)
catch e
throw(
JuliaHubError("Unable to parse 'inputs' JSON for job $jobname:\n$(inputs)",
Expand Down
2 changes: 1 addition & 1 deletion src/jobs/logging-legacy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ function _get_job_logs_legacy(
# If the request was successful, we should be able to parse the logs. But if there was an error,
# we might also get back a JSON with a success=false field.
body = String(r.body)
jb = JSON.parse(body)
jb = JSON.parse(body; dicttype=Dict)
if jb isa Dict && !get(jb, "success", true)
throw(
JuliaHubError(
Expand Down
2 changes: 1 addition & 1 deletion src/node.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function nodespecs(; auth::Authentication=__auth__())
r = _api_nodespecs(auth)
if r.status == 200
try
json = JSON.parse(String(r.body))
json = JSON.parse(String(r.body); dicttype=Dict)
if json["success"]
nodes = [
NodeSpec(n) for n in json["node_specs"]
Expand Down
2 changes: 1 addition & 1 deletion src/restapi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function Base.getproperty(r::_RESTResponse, name::Symbol)
if name in fieldnames(_RESTResponse)
getfield(r, name)
elseif name == :json
JSON.parse(getfield(r, :body))
JSON.parse(getfield(r, :body); dicttype=Dict)
else
error("_RESTResponse has no property $name")
end
Expand Down
15 changes: 8 additions & 7 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function _parse_response_json(r::HTTP.Response, ::Type{T})::Tuple{T, String} whe
end
function _parse_response_json(s::AbstractString, ::Type{T})::Tuple{T, String} where {T}
object = try
JSON.parse(s)
JSON.parse(s; dicttype=Dict)
catch e
throw(
JuliaHubError(
Expand All @@ -167,7 +167,7 @@ function _parse_response_json(s::AbstractString, ::Type{T})::Tuple{T, String} wh
end

function _get_json(
json::Dict, key::AbstractString, ::Type{T}; msg::Union{AbstractString, Nothing}=nothing
json::AbstractDict, key::AbstractString, ::Type{T}; msg::Union{AbstractString, Nothing}=nothing
)::T where {T}
value = get(json, key) do
errormsg = """
Expand All @@ -186,7 +186,7 @@ function _get_json(
end

function _get_json_or(
json::Dict,
json::AbstractDict,
key::AbstractString,
::Type{T},
default::U=nothing;
Expand All @@ -209,7 +209,8 @@ end
# A key point, though, is that it will throw a JuliaHubError if the server response is somehow
# invalid and we can't parse/convert it properly.
function _get_json_convert(
json::Dict, key::AbstractString, ::Type{UUIDs.UUID}; msg::Union{AbstractString, Nothing}=nothing
json::AbstractDict, key::AbstractString, ::Type{UUIDs.UUID};
msg::Union{AbstractString, Nothing}=nothing,
)::UUIDs.UUID
uuid_str = _get_json(json, key, String; msg)
uuid = tryparse(UUIDs.UUID, uuid_str)
Expand Down Expand Up @@ -355,7 +356,7 @@ function _walkfiles(f::Base.Callable, root::AbstractString; descend::Base.Callab
end
end

function _json_get(d::Dict, key, ::Type{T}; var::AbstractString, parse=false) where {T}
function _json_get(d::AbstractDict, key, ::Type{T}; var::AbstractString, parse=false) where {T}
haskey(d, key) || _throw_jsonerror(var, "key `$key` missing", d)
if parse
isa(d[key], AbstractString) || _throw_jsonerror(
Expand All @@ -372,7 +373,7 @@ function _json_get(d::Dict, key, ::Type{T}; var::AbstractString, parse=false) wh
end
end

function _throw_jsonerror(var::AbstractString, msg::AbstractString, json::Dict)
function _throw_jsonerror(var::AbstractString, msg::AbstractString, json::AbstractDict)
e = JuliaHubError(
"""
Invalid JSON response from JuliaHub ($var): $msg
Expand All @@ -383,7 +384,7 @@ function _throw_jsonerror(var::AbstractString, msg::AbstractString, json::Dict)
end

# Checks that the 'success' field is set and === true
function _json_check_success(json::Dict; var::AbstractString)
function _json_check_success(json::AbstractDict; var::AbstractString)
success = _json_get(json, "success", Bool; var)
success || throw(JuliaHubError(
"""
Expand Down
4 changes: 2 additions & 2 deletions test/jobs-exposed-port-live.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function test_job_with_exposed_port(job::JuliaHub.Job; check_input::Bool=false,
job = wait_submission(job)
let r = wait_exposed_job_502(job)
@test r.status == 200
json = JSON.parse(String(r.body))
json = JSON.parse(String(r.body); dicttype=Dict)
@test json isa AbstractDict
@test get(json, "success", nothing) === true
@test get(json, "port", nothing) == port
Expand All @@ -34,7 +34,7 @@ function test_job_with_exposed_port(job::JuliaHub.Job; check_input::Bool=false,
# gets incremented correctly.
let r = JuliaHub.request(job, "GET", "/"; auth, status_exception=false)
@test r.status == 200
json = JSON.parse(String(r.body))
json = JSON.parse(String(r.body); dicttype=Dict)
@test json isa AbstractDict
@test get(json, "success", nothing) === true
@test get(json, "nrequests", nothing) == 2
Expand Down
14 changes: 7 additions & 7 deletions test/jobs-live.jl
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ end
@test job.status == "Failed"
# Even though the job failed, any RESULTS set before the error are still stored
@test !isempty(job.results)
let results = JSON.parse(job.results)
let results = JSON.parse(job.results; dicttype=Dict)
@test results isa AbstractDict
@test haskey(results, "x")
@test results["x"] == 42
Expand All @@ -220,7 +220,7 @@ end
job = JuliaHub.wait_job(job)
@test test_job_done_and_not_failed(job, "Completed")
@test !isempty(job.results)
let results = JSON.parse(job.results)
let results = JSON.parse(job.results; dicttype=Dict)
@test results isa AbstractDict
@test haskey(results, "vs")
@test length(results["vs"]) == 2
Expand All @@ -246,7 +246,7 @@ end
job = JuliaHub.wait_job(job)
@test test_job_done_and_not_failed(job, "Completed")
@test !isempty(job.results)
let results = JSON.parse(job.results)
let results = JSON.parse(job.results; dicttype=Dict)
@test results isa AbstractDict
@test haskey(results, "vs")
@test length(results["vs"]) == 5
Expand All @@ -268,7 +268,7 @@ end
job = JuliaHub.wait_job(job)
@test test_job_done_and_not_failed(job, "Completed")
@test !isempty(job.results)
let results = JSON.parse(job.results)
let results = JSON.parse(job.results; dicttype=Dict)
@test results isa AbstractDict
@test haskey(results, "datastructures_version")
@test VersionNumber(results["datastructures_version"]) == v"0.17.0"
Expand All @@ -288,7 +288,7 @@ end
job = JuliaHub.wait_job(job)
@test test_job_done_and_not_failed(job, "Completed")
@test !isempty(job.results)
let results = JSON.parse(job.results)
let results = JSON.parse(job.results; dicttype=Dict)
@test results isa AbstractDict
@test haskey(results, "datastructures_version")
@test VersionNumber(results["datastructures_version"]) > v"0.17.0"
Expand All @@ -315,7 +315,7 @@ if v"1.10" <= Base.VERSION < v"1.12"
@test JuliaHub.job_file(job, :input, "appbundle.tar") isa JuliaHub.JobFile
# Test the results values
@test !isempty(job.results)
let results = JSON.parse(job.results)
let results = JSON.parse(job.results; dicttype=Dict)
@test results isa AbstractDict
@test haskey(results, "datastructures_version")
@test VersionNumber(results["datastructures_version"]) == v"0.17.0"
Expand Down Expand Up @@ -432,7 +432,7 @@ end
@test test_job_done_and_not_failed(job, "Completed")
@test job._json["sysimage_build"] === true
@test !isempty(job.results)
let results = JSON.parse(job.results)
let results = JSON.parse(job.results; dicttype=Dict)
@test results isa AbstractDict
@test results["in_sysimage"] === true
@test results["loaded_modules_before_import"] === true
Expand Down
2 changes: 1 addition & 1 deletion test/jobs-windows-live.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@test job.status == "Completed"
@test job.alias == full_alias
@test !isempty(job.results)
let results = JSON.parse(job.results)
let results = JSON.parse(job.results; dicttype=Dict)
@test results isa AbstractDict
@test haskey(results, "iswindows")
@test results["iswindows"] === true
Expand Down
8 changes: 4 additions & 4 deletions test/mocking.jl
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ function _restcall_mocked(method, url, headers, payload; query)
) |> jsonresponse(200)
end
elseif (method == :POST) && endswith(url, "juliaruncloud/extend_job_time_limit")
payload = JSON.parse(payload)
payload = JSON.parse(payload; dicttype=Dict)
idx = findfirst(isequal(payload["jobname"]), job_names)
if isnothing(idx)
JuliaHub._RESTResponse(403, "User does not have access to this job")
Expand Down Expand Up @@ -401,7 +401,7 @@ function _restcall_mocked(method, url, headers, payload; query)
dataset = URIs.unescapeuri(match(DATASET_REGEX, url)[1])
if "username/$(dataset)" ∈ existing_datasets
if haskey(MOCK_JULIAHUB_STATE, :dataset_params)
merge!(MOCK_JULIAHUB_STATE[:dataset_params], JSON.parse(payload))
merge!(MOCK_JULIAHUB_STATE[:dataset_params], JSON.parse(payload; dicttype=Dict))
end
Dict{String, Any}(
"name" => dataset,
Expand All @@ -411,7 +411,7 @@ function _restcall_mocked(method, url, headers, payload; query)
return JuliaHub._RESTResponse(404, "Dataset $(dataset) does not exist.")
end
elseif (method == :POST) && endswith(url, "/user/datasets")
payload = JSON.parse(payload)
payload = JSON.parse(payload; dicttype=Dict)
dataset, type = payload["name"], payload["type"]
if "$(MOCK_USERNAME)/$(dataset)" in existing_datasets
JuliaHub._RESTResponse(409, "Dataset $(dataset) exists")
Expand All @@ -426,7 +426,7 @@ function _restcall_mocked(method, url, headers, payload; query)
dataset, is_user = let m = match(DATASET_VERSIONS_REGEX, url)
URIs.unescapeuri(m[2]), m[1] == "user/"
end
payload = JSON.parse(something(payload, "{}"))
payload = JSON.parse(something(payload, "{}"); dicttype=Dict)
if isempty(payload) || !haskey(payload, "action")
is_existing_dataset = if is_user
"$(MOCK_USERNAME)/$(dataset)" in existing_datasets
Expand Down
Loading