From 25de0299924db4623ccc47c07c0c6360e88410b3 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Thu, 21 Apr 2022 15:14:01 +0200 Subject: [PATCH 1/2] fix(database): casting of float values --- app/init.php | 2 +- app/workers/database.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/init.php b/app/init.php index fd509297f6..d4bb38c5b4 100644 --- a/app/init.php +++ b/app/init.php @@ -181,7 +181,7 @@ if(!empty($user) || !empty($pass)) { */ Database::addFilter('casting', function($value) { - return json_encode(['value' => $value]); + return json_encode(['value' => $value], JSON_PRESERVE_ZERO_FRACTION); }, function($value) { if (is_null($value)) { diff --git a/app/workers/database.php b/app/workers/database.php index d95ce122d0..5fd3e16e25 100644 --- a/app/workers/database.php +++ b/app/workers/database.php @@ -71,6 +71,11 @@ class DatabaseV1 extends Worker $dbForConsole = $this->getConsoleDB(); $dbForProject = $this->getProjectDB($projectId); + /** + * Fetch attribute from the database, since with Resque float values are loosing informations. + */ + $attribute = $dbForProject->getDocument('attributes', $attribute->getId()); + $event = 'database.attributes.update'; $collectionId = $collection->getId(); $key = $attribute->getAttribute('key', ''); From 25c7127f760fcf92a8d35d404307a3544fcc32f7 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Thu, 21 Apr 2022 15:20:53 +0200 Subject: [PATCH 2/2] tests: add float default 0 to database --- tests/e2e/Services/Database/DatabaseBase.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/e2e/Services/Database/DatabaseBase.php b/tests/e2e/Services/Database/DatabaseBase.php index 94e737ff37..640ab99361 100644 --- a/tests/e2e/Services/Database/DatabaseBase.php +++ b/tests/e2e/Services/Database/DatabaseBase.php @@ -1428,6 +1428,7 @@ trait DatabaseBase ]), [ 'key' => 'probability', 'required' => false, + 'default' => 0, 'min' => 0, 'max' => 1, ]);