Skip to content

Commit

Permalink
Fixed an issue where decoded CodableContextKey values became inaccesi…
Browse files Browse the repository at this point in the history
…ble after the first access (#7)
  • Loading branch information
Supereg authored Feb 7, 2022
1 parent fe22deb commit f655813
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Sources/ApodiniContext/Context.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ public struct Context: ContextKeyRetrievable {
}

do {
return try Key.decode(from: dataValue)
let value = try Key.decode(from: dataValue)
boxedEntries.entries[ObjectIdentifier(key)] = StoredContextValue(key: key, value: value)
return value
} catch {
fatalError("Error occurred when trying to decode `CodableContextKey` `\(Key.self)` with stored value '\(dataValue)': \(error)")
}
Expand Down
2 changes: 2 additions & 0 deletions Tests/ApodiniContextTests/ContextKeyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ class ContextKeyTests: XCTestCase {
)

let decodedContext = try decoder.decode(Context.self, from: encodedContext)
XCTAssertEqual(decodedContext.get(valueFor: CodableStringContextKey.self), "Hello Mars")
XCTAssertEqual(decodedContext.get(valueFor: CodableStringContextKey.self), "Hello Mars")

decodedContext.unsafeAdd(CodableStringContextKey.self, value: "Hello Saturn", allowOverwrite: true)
XCTAssertEqual(decodedContext.get(valueFor: CodableStringContextKey.self), "Hello Saturn")
Expand Down

0 comments on commit f655813

Please sign in to comment.