Skip to content

Commit 2111324

Browse files
committed
json 1.0 compat
1 parent d7e5cc3 commit 2111324

File tree

10 files changed

+26
-26
lines changed

10 files changed

+26
-26
lines changed

src/batchimages.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ function _batchimages_legacy(auth::Authentication)
141141
r = _restcall(auth, :GET, "juliaruncloud", "get_image_options")
142142
if r.status == 200
143143
try
144-
json = JSON.parse(String(r.body))
144+
json = JSON.parse(String(r.body); dicttype=Dict)
145145
if json["success"] && haskey(json, "image_options")
146146
image_options = json["image_options"]
147147
default_options = [

src/jobs/jobs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ struct Job
233233
Dict{String, Any}() # TODO: drop Nothing?
234234
else
235235
try
236-
JSON.parse(unescape_string(inputs))
236+
JSON.parse(unescape_string(inputs); dicttype=Dict)
237237
catch e
238238
throw(
239239
JuliaHubError("Unable to parse 'inputs' JSON for job $jobname:\n$(inputs)",

src/jobs/logging-legacy.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ function _get_job_logs_legacy(
223223
# If the request was successful, we should be able to parse the logs. But if there was an error,
224224
# we might also get back a JSON with a success=false field.
225225
body = String(r.body)
226-
jb = JSON.parse(body)
226+
jb = JSON.parse(body; dicttype=Dict)
227227
if jb isa Dict && !get(jb, "success", true)
228228
throw(
229229
JuliaHubError(

src/node.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function nodespecs(; auth::Authentication=__auth__())
8181
r = _api_nodespecs(auth)
8282
if r.status == 200
8383
try
84-
json = JSON.parse(String(r.body))
84+
json = JSON.parse(String(r.body); dicttype=Dict)
8585
if json["success"]
8686
nodes = [
8787
NodeSpec(n) for n in json["node_specs"]

src/restapi.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function Base.getproperty(r::_RESTResponse, name::Symbol)
5151
if name in fieldnames(_RESTResponse)
5252
getfield(r, name)
5353
elseif name == :json
54-
JSON.parse(getfield(r, :body))
54+
JSON.parse(getfield(r, :body); dicttype=Dict)
5555
else
5656
error("_RESTResponse has no property $name")
5757
end

src/utils.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ function _parse_response_json(r::HTTP.Response, ::Type{T})::Tuple{T, String} whe
147147
end
148148
function _parse_response_json(s::AbstractString, ::Type{T})::Tuple{T, String} where {T}
149149
object = try
150-
JSON.parse(s)
150+
JSON.parse(s; dicttype=Dict)
151151
catch e
152152
throw(
153153
JuliaHubError(
@@ -167,7 +167,7 @@ function _parse_response_json(s::AbstractString, ::Type{T})::Tuple{T, String} wh
167167
end
168168

169169
function _get_json(
170-
json::Dict, key::AbstractString, ::Type{T}; msg::Union{AbstractString, Nothing}=nothing
170+
json::AbstractDict, key::AbstractString, ::Type{T}; msg::Union{AbstractString, Nothing}=nothing
171171
)::T where {T}
172172
value = get(json, key) do
173173
errormsg = """
@@ -186,7 +186,7 @@ function _get_json(
186186
end
187187

188188
function _get_json_or(
189-
json::Dict,
189+
json::AbstractDict,
190190
key::AbstractString,
191191
::Type{T},
192192
default::U=nothing;
@@ -209,7 +209,7 @@ end
209209
# A key point, though, is that it will throw a JuliaHubError if the server response is somehow
210210
# invalid and we can't parse/convert it properly.
211211
function _get_json_convert(
212-
json::Dict, key::AbstractString, ::Type{UUIDs.UUID}; msg::Union{AbstractString, Nothing}=nothing
212+
json::AbstractDict, key::AbstractString, ::Type{UUIDs.UUID}; msg::Union{AbstractString, Nothing}=nothing
213213
)::UUIDs.UUID
214214
uuid_str = _get_json(json, key, String; msg)
215215
uuid = tryparse(UUIDs.UUID, uuid_str)
@@ -355,7 +355,7 @@ function _walkfiles(f::Base.Callable, root::AbstractString; descend::Base.Callab
355355
end
356356
end
357357

358-
function _json_get(d::Dict, key, ::Type{T}; var::AbstractString, parse=false) where {T}
358+
function _json_get(d::AbstractDict, key, ::Type{T}; var::AbstractString, parse=false) where {T}
359359
haskey(d, key) || _throw_jsonerror(var, "key `$key` missing", d)
360360
if parse
361361
isa(d[key], AbstractString) || _throw_jsonerror(
@@ -372,7 +372,7 @@ function _json_get(d::Dict, key, ::Type{T}; var::AbstractString, parse=false) wh
372372
end
373373
end
374374

375-
function _throw_jsonerror(var::AbstractString, msg::AbstractString, json::Dict)
375+
function _throw_jsonerror(var::AbstractString, msg::AbstractString, json::AbstractDict)
376376
e = JuliaHubError(
377377
"""
378378
Invalid JSON response from JuliaHub ($var): $msg
@@ -383,7 +383,7 @@ function _throw_jsonerror(var::AbstractString, msg::AbstractString, json::Dict)
383383
end
384384

385385
# Checks that the 'success' field is set and === true
386-
function _json_check_success(json::Dict; var::AbstractString)
386+
function _json_check_success(json::AbstractDict; var::AbstractString)
387387
success = _json_get(json, "success", Bool; var)
388388
success || throw(JuliaHubError(
389389
"""

test/jobs-exposed-port-live.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function test_job_with_exposed_port(job::JuliaHub.Job; check_input::Bool=false,
1919
job = wait_submission(job)
2020
let r = wait_exposed_job_502(job)
2121
@test r.status == 200
22-
json = JSON.parse(String(r.body))
22+
json = JSON.parse(String(r.body); dicttype=Dict)
2323
@test json isa AbstractDict
2424
@test get(json, "success", nothing) === true
2525
@test get(json, "port", nothing) == port
@@ -34,7 +34,7 @@ function test_job_with_exposed_port(job::JuliaHub.Job; check_input::Bool=false,
3434
# gets incremented correctly.
3535
let r = JuliaHub.request(job, "GET", "/"; auth, status_exception=false)
3636
@test r.status == 200
37-
json = JSON.parse(String(r.body))
37+
json = JSON.parse(String(r.body); dicttype=Dict)
3838
@test json isa AbstractDict
3939
@test get(json, "success", nothing) === true
4040
@test get(json, "nrequests", nothing) == 2

test/jobs-live.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ end
199199
@test job.status == "Failed"
200200
# Even though the job failed, any RESULTS set before the error are still stored
201201
@test !isempty(job.results)
202-
let results = JSON.parse(job.results)
202+
let results = JSON.parse(job.results; dicttype=Dict)
203203
@test results isa AbstractDict
204204
@test haskey(results, "x")
205205
@test results["x"] == 42
@@ -220,7 +220,7 @@ end
220220
job = JuliaHub.wait_job(job)
221221
@test test_job_done_and_not_failed(job, "Completed")
222222
@test !isempty(job.results)
223-
let results = JSON.parse(job.results)
223+
let results = JSON.parse(job.results; dicttype=Dict)
224224
@test results isa AbstractDict
225225
@test haskey(results, "vs")
226226
@test length(results["vs"]) == 2
@@ -246,7 +246,7 @@ end
246246
job = JuliaHub.wait_job(job)
247247
@test test_job_done_and_not_failed(job, "Completed")
248248
@test !isempty(job.results)
249-
let results = JSON.parse(job.results)
249+
let results = JSON.parse(job.results; dicttype=Dict)
250250
@test results isa AbstractDict
251251
@test haskey(results, "vs")
252252
@test length(results["vs"]) == 5
@@ -268,7 +268,7 @@ end
268268
job = JuliaHub.wait_job(job)
269269
@test test_job_done_and_not_failed(job, "Completed")
270270
@test !isempty(job.results)
271-
let results = JSON.parse(job.results)
271+
let results = JSON.parse(job.results; dicttype=Dict)
272272
@test results isa AbstractDict
273273
@test haskey(results, "datastructures_version")
274274
@test VersionNumber(results["datastructures_version"]) == v"0.17.0"
@@ -288,7 +288,7 @@ end
288288
job = JuliaHub.wait_job(job)
289289
@test test_job_done_and_not_failed(job, "Completed")
290290
@test !isempty(job.results)
291-
let results = JSON.parse(job.results)
291+
let results = JSON.parse(job.results; dicttype=Dict)
292292
@test results isa AbstractDict
293293
@test haskey(results, "datastructures_version")
294294
@test VersionNumber(results["datastructures_version"]) > v"0.17.0"
@@ -315,7 +315,7 @@ if v"1.10" <= Base.VERSION < v"1.12"
315315
@test JuliaHub.job_file(job, :input, "appbundle.tar") isa JuliaHub.JobFile
316316
# Test the results values
317317
@test !isempty(job.results)
318-
let results = JSON.parse(job.results)
318+
let results = JSON.parse(job.results; dicttype=Dict)
319319
@test results isa AbstractDict
320320
@test haskey(results, "datastructures_version")
321321
@test VersionNumber(results["datastructures_version"]) == v"0.17.0"
@@ -432,7 +432,7 @@ end
432432
@test test_job_done_and_not_failed(job, "Completed")
433433
@test job._json["sysimage_build"] === true
434434
@test !isempty(job.results)
435-
let results = JSON.parse(job.results)
435+
let results = JSON.parse(job.results; dicttype=Dict)
436436
@test results isa AbstractDict
437437
@test results["in_sysimage"] === true
438438
@test results["loaded_modules_before_import"] === true

test/jobs-windows-live.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
@test job.status == "Completed"
2727
@test job.alias == full_alias
2828
@test !isempty(job.results)
29-
let results = JSON.parse(job.results)
29+
let results = JSON.parse(job.results; dicttype=Dict)
3030
@test results isa AbstractDict
3131
@test haskey(results, "iswindows")
3232
@test results["iswindows"] === true

test/mocking.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ function _restcall_mocked(method, url, headers, payload; query)
350350
) |> jsonresponse(200)
351351
end
352352
elseif (method == :POST) && endswith(url, "juliaruncloud/extend_job_time_limit")
353-
payload = JSON.parse(payload)
353+
payload = JSON.parse(payload; dicttype=Dict)
354354
idx = findfirst(isequal(payload["jobname"]), job_names)
355355
if isnothing(idx)
356356
JuliaHub._RESTResponse(403, "User does not have access to this job")
@@ -401,7 +401,7 @@ function _restcall_mocked(method, url, headers, payload; query)
401401
dataset = URIs.unescapeuri(match(DATASET_REGEX, url)[1])
402402
if "username/$(dataset)" existing_datasets
403403
if haskey(MOCK_JULIAHUB_STATE, :dataset_params)
404-
merge!(MOCK_JULIAHUB_STATE[:dataset_params], JSON.parse(payload))
404+
merge!(MOCK_JULIAHUB_STATE[:dataset_params], JSON.parse(payload; dicttype=Dict))
405405
end
406406
Dict{String, Any}(
407407
"name" => dataset,
@@ -411,7 +411,7 @@ function _restcall_mocked(method, url, headers, payload; query)
411411
return JuliaHub._RESTResponse(404, "Dataset $(dataset) does not exist.")
412412
end
413413
elseif (method == :POST) && endswith(url, "/user/datasets")
414-
payload = JSON.parse(payload)
414+
payload = JSON.parse(payload; dicttype=Dict)
415415
dataset, type = payload["name"], payload["type"]
416416
if "$(MOCK_USERNAME)/$(dataset)" in existing_datasets
417417
JuliaHub._RESTResponse(409, "Dataset $(dataset) exists")
@@ -426,7 +426,7 @@ function _restcall_mocked(method, url, headers, payload; query)
426426
dataset, is_user = let m = match(DATASET_VERSIONS_REGEX, url)
427427
URIs.unescapeuri(m[2]), m[1] == "user/"
428428
end
429-
payload = JSON.parse(something(payload, "{}"))
429+
payload = JSON.parse(something(payload, "{}"); dicttype=Dict)
430430
if isempty(payload) || !haskey(payload, "action")
431431
is_existing_dataset = if is_user
432432
"$(MOCK_USERNAME)/$(dataset)" in existing_datasets

0 commit comments

Comments
 (0)