Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading a ledger with decimal value transacted throws coercion error #436

Closed
mpoffald opened this issue Apr 3, 2023 · 0 comments · Fixed by #446
Closed

Loading a ledger with decimal value transacted throws coercion error #436

mpoffald opened this issue Apr 3, 2023 · 0 comments · Fixed by #446
Assignees
Labels
bug Something isn't working as expected

Comments

@mpoffald
Copy link
Contributor

mpoffald commented Apr 3, 2023

Overview

When using a file conn, committing a decimal value and then attempting to load the ledger fails with a coercion error:

ERROR fluree.db.json-ld.api - #error {
 :cause "Data type 5 cannot be coerced from provided value: 99.99."
 :data {:status 400, :error :db/shacl-value-coercion}
 :via
 [{:type clojure.lang.ExceptionInfo
   :message "Data type 5 cannot be coerced from provided value: 99.99."
   :data {:status 400, :error :db/shacl-value-coercion}
   :at [fluree.db.datatype$from_expanded invokeStatic "datatype.cljc" 408]}]
 :trace
 [[fluree.db.datatype$from_expanded invokeStatic "datatype.cljc" 408]
  [fluree.db.datatype$from_expanded invoke "datatype.cljc" 391]
  [fluree.db.json_ld.reify$assert_v_maps$fn__40175$state_machine__7814__auto____40204$fn__40211 invoke "reify.cljc" 139]
  [fluree.db.json_ld.reify$assert_v_maps$fn__40175$state_machine__7814__auto____40204 invoke "reify.cljc" 139]
  [clojure.core.async.impl.runtime$run_state_machine invokeStatic "runtime.clj" 62]
  [clojure.core.async.impl.runtime$run_state_machine invoke "runtime.clj" 61]
  [clojure.core.async.impl.runtime$run_state_machine_wrapped invokeStatic "runtime.clj" 66]
  [clojure.core.async.impl.runtime$run_state_machine_wrapped invoke "runtime.clj" 64]
  [fluree.db.json_ld.reify$assert_v_maps$fn__40175 invoke "reify.cljc" 139]
  [clojure.lang.AFn run "AFn.java" 22]
  [java.util.concurrent.ThreadPoolExecutor runWorker "ThreadPoolExecutor.java" 1136]
  [java.util.concurrent.ThreadPoolExecutor$Worker run "ThreadPoolExecutor.java" 635]
  [clojure.core.async.impl.concurrent$counted_thread_factory$reify__1375$fn__1376 invoke "concurrent.clj" 29]
  [clojure.lang.AFn run "AFn.java" 22]
  [java.lang.Thread run "Thread.java" 833]]}

Steps to reproduce

(require '[fluree.db.test-utils :as test-utils]) 
(def decimal-txn [{:context      {:ex "http://example.org/ns/"}
                   :id           :ex/widget
                   :type         :schema/Product,
                   :schema/price 99.99}]) 

(def file-conn @(fluree/connect {:method :file
                                   :storage-path "dev/data"
                                   :defaults
                                   {:context (merge test-utils/default-context {:ex "http://example.org/ns/"})
                                    :did did}})) 


(def ledger @(fluree/create file-conn "user/decimal")) 

(def db1 @(fluree/stage
            (fluree/db ledger)
            decimal-txn)) 



(def db2 @(fluree/commit! ledger db1)) 


@(fluree/load file-conn (-> ledger :alias)) 
;;=> coercion error

Notes

  1. I could not reproduce the error with a mem conn:
(def test-conn (test-utils/create-conn)) 
(def test-ledger @(fluree/create test-conn "decimals")) 

(def db1 @(test-utils/transact test-ledger [{:context      {:ex "http://example.org/ns/"}
                                             :id           :ex/widget
                                             :type         :schema/Product,
                                             :schema/price 99.99}])) 

  @(fluree/load test-conn (-> test-ledger :alias)) 
;;=> no error
  1. This was the commit file that was written out in the file conn example:
{"@context":{"ex":"http://example.org/ns/","f":"https://ns.flur.ee/ledger#","f:assert":{"@container":"@graph"},"id":"@id","rdf":"http://www.w3.org/1999/02/22-rdf-syntax-ns#","rdfs":"http://www.w3.org/2000/01/rdf-schema#","schema":"http://schema.org/","sh":"http://www.w3.org/ns/shacl#","type":"@type","xsd":"http://www.w3.org/2001/XMLSchema#"},

"f:assert":
[{"id":"ex:widget",
"schema:price":99.99,
"type":"schema:Product"}],

"f:flakes":12,"f:size":1048,"f:t":1,"f:v":0,"id":"fluree:db:sha256:bhgqezx6gbtnqi6zz4t7tbx6jt75za4hgxop2nyb4oxl2pngbedq","type":["f:DB"]}
  1. Here are the logs from loading the file conn, just before the error:
DEBUG fluree.db.json-ld.reify - assert-v-maps v-map: {:value 99.99M, :type nil, :idx ["f:assert" 0 "schema:price"]}
DEBUG fluree.db.json-ld.reify - assert-v-maps id: "http://example.org/ns/widget"
DEBUG fluree.db.datatype - from-expanded type: 5
DEBUG fluree.db.datatype - coerce value: 99.99M to type: 5

vs with mem conn:

DEBUG fluree.db.json-ld.reify - assert-v-maps v-map: {:value 99.99, :type nil, :idx ["f:assert" 0 "schema:price"]}
DEBUG fluree.db.json-ld.reify - assert-v-maps id: "http://example.org/ns/widget"
DEBUG fluree.db.datatype - from-expanded type: 5
DEBUG fluree.db.datatype - coerce value: 99.99 to type: 5
@mpoffald mpoffald added the bug Something isn't working as expected label Apr 3, 2023
@mpoffald mpoffald changed the title Loading a db with decimal value throws coercion error Loading a ledger with decimal value transacted throws coercion error Apr 3, 2023
@cap10morgan cap10morgan self-assigned this Apr 6, 2023
cap10morgan added a commit that referenced this issue Apr 6, 2023
To help show when issue #436 is fixed
cap10morgan added a commit that referenced this issue Apr 6, 2023
...like when loading a ledger w/ file conn. Fixes #436.
cap10morgan added a commit that referenced this issue Apr 6, 2023
...like when loading a ledger w/ file conn. Fixes #436.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants