JSON-ify credit values with perfect precision if we introduce job types with fractional costs
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start by reading apps/api/src/hyp3_api/routes.py and tracing how /costs, /jobs, and /user responses serialize credit values with flask.jsonify; then check how clients deserialize those values. The issue asks for a representation that preserves credit precision through serialization and deserialization while keeping float job parameters compatible. Done means credit values round-trip without precision loss across these API responses.
Written by the indexing model from the issue text.
Description
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 https://github.com/ASFHyP3/hyp3/pull/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:
/costsreturns a table of credit costs/jobsendpoints include acredit_costfield for each job/userincludes aremaining_creditsfield
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.
- Dominant language
- Python
- Stars
- 53
- Forks
- 13
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 20
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ASFHyP3/hyp3
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Most static tests fail when a date-like string is provided as an example value in a job spec YAMLOpenbug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
Jira Bug
Difficulty 1/5 1-3 hours Newbie friendliness 77/100
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
FinanceFlash/unvibecode#699 ·
Maintainers usually reply within 1 day
-
enhancement Website
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
OWASP/OWASP-Hunting#96 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
micropython/micropython#19942 ·
Maintainers usually reply within 1 day
-
A rebuild posts "not part of this build" success to the commit's failed `nix-build` gate and effectsPossibly taken @Padraic-O-Mhuiris claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
`epoch.Integer` raises a raw OverflowError for integers too large to convert to a floatPossibly taken @arindam77 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
pydantic/pydantic-extra-types#479 ·
Maintainers usually reply within 1 day