• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aiidateam / aiida_core / 6586
74%

Build:
DEFAULT BRANCH: develop
Ran 02 Jul 2019 10:34AM UTC
Jobs 4
Files 403
Run time 9min
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

pending completion
6586

push

travis-ci

sphuber
Enforcing specific float precision in `clean_value` (#3108)

The purpose of the `clean_value` utility function is to convert data
that is to be stored in node attributes or extras in such a way that it
becomes:

  1. JSON serializable, since the database model fields use JSONB
  2. The serialization/deserialization roundtrip results in no changes

The last step is especially important for the hashing of nodes. If the
serialization roundtrip changes the values, the hash computed before the
node is stored, will be different from the hash computed from its data
after it is stored.

A particularly difficult case for the `clean_value` are floats. The JSON
serialized value in the database may have a different precision than the
original float specified in memory. To make the serialization roundtrip
mutationless, all floats are rounded to 14 significant digits. This is
just below machine precision and that of the current database backends
and will guarantee that the rounded float will not change.

However, even with this rounding there is another complication. Floats
that are sufficiently large and can be interpreted as integers, will be
automatically converted to a long int by the database. Changing the type
will change the hash and destroy the desired null operation for the
serialization roundtrip. Since we cannot control the behavior of the
type casting of the database, we perform the casting of the float to an
int ourselves in `clean_values`. First the normal float rounding is
applied. If the resulting float correspond to an integer, i.e. it only
contains zeroes after the comma, it is converted to an integer. Changing
the types of floats in this way might be unexpected to the user, but it
is the only way to guarantee the hashing works, which is a tradeoff we
are willing to make.

In this commit, we enforce a maximum precision of 14 digits for floats.
This is a change with respect to what used to be done before. Since we
... (continued)

24 of 24 new or added lines in 4 files covered. (100.0%)

24057 of 32431 relevant lines covered (74.18%)

2.75 hits per line

Jobs
ID Job ID Ran Files Coverage
5 6586.5 (TEST_AIIDA_BACKEND=django TEST_TYPE="tests") 02 Jul 2019 10:34AM UTC 0
67.91
Travis Job 6586.5
6 6586.6 (TEST_AIIDA_BACKEND=django TEST_TYPE="tests") 02 Jul 2019 10:41AM UTC 0
67.86
Travis Job 6586.6
7 6586.7 (TEST_AIIDA_BACKEND=sqlalchemy TEST_TYPE="tests") 02 Jul 2019 10:40AM UTC 0
69.5
Travis Job 6586.7
8 6586.8 (TEST_AIIDA_BACKEND=sqlalchemy TEST_TYPE="tests") 02 Jul 2019 10:41AM UTC 0
69.47
Travis Job 6586.8
Source Files on build 6586
Detailed source file information is not available for this build.
  • Back to Repo
  • Travis Build #6586
  • da0a5c66 on github
  • Prev Build on develop (#6582)
  • Next Build on develop (#6592)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc