You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: The above link is accessible only to members of ASF.
As part of the configurable job cost implementation in #2072, we've settled on always handling credit values as decimal.Decimal objects so that we always perform credit calculations using fixed-point arithmetic rather than floating-point arithmetic. This is how banks and other financial institutions perform calculations with currency, and will be important for avoiding precision errors if we ever introduce a job type with a fractional cost, which would almost certainly be less than 1.0.
Currently, all of our API responses include at least one credits value:
/costs returns a table of credit costs
/jobs endpoints include a credit_cost field for each job
/user includes a remaining_credits field
The responses are all serialized as JSON using flask.jsonify. By default, jsonify would serialize Decimal objects as str, but we define a CustomEncoder class in apps/api/src/hyp3_api/routes.py, which converts Decimal to float.
This should be fine for now, as we don't have any fractional job costs. However, if we ever introduce any job types with fractional costs, we should revisit how to serialize credit values in our API responses. For example, the default jsonify behavior of converting Decimal to str may be more appropriate (though we wouldn't want to break how we serialize float job parameter values). We want to ensure that credit values are serialized with perfect precision in our API responses, and that they can be de-serialized with perfect precision by the client.
The text was updated successfully, but these errors were encountered:
Jira: https://asfdaac.atlassian.net/browse/TOOL-2609
Note: The above link is accessible only to members of ASF.
As part of the configurable job cost implementation in #2072, we've settled on always handling credit values as
decimal.Decimal
objects so that we always perform credit calculations using fixed-point arithmetic rather than floating-point arithmetic. This is how banks and other financial institutions perform calculations with currency, and will be important for avoiding precision errors if we ever introduce a job type with a fractional cost, which would almost certainly be less than1.0
.Currently, all of our API responses include at least one credits value:
/costs
returns a table of credit costs/jobs
endpoints include acredit_cost
field for each job/user
includes aremaining_credits
fieldThe responses are all serialized as JSON using
flask.jsonify
. By default,jsonify
would serializeDecimal
objects asstr
, but we define aCustomEncoder
class inapps/api/src/hyp3_api/routes.py
, which convertsDecimal
tofloat
.This should be fine for now, as we don't have any fractional job costs. However, if we ever introduce any job types with fractional costs, we should revisit how to serialize credit values in our API responses. For example, the default
jsonify
behavior of convertingDecimal
tostr
may be more appropriate (though we wouldn't want to break how we serializefloat
job parameter values). We want to ensure that credit values are serialized with perfect precision in our API responses, and that they can be de-serialized with perfect precision by the client.The text was updated successfully, but these errors were encountered: