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

Fatal error: ceil(): Argument #1 ($num) must be of type int|float, string given in BaseDraw.php #19940

Open
tsteur opened this issue Nov 2, 2022 · 19 comments
Labels
Bug For errors / faults / flaws / inconsistencies etc.

Comments

@tsteur
Copy link
Member

tsteur commented Nov 2, 2022

See details below:

Error: {"message":"ceil(): Argument #1 ($num) must be of type int|float, string given","file":"/vendor/szymach/c-pchart/src/BaseDraw.php","line":383,"request_id":"d387f","backtrace":" on /vendor/szymach/c-pchart/src/BaseDraw.php(383)\n#0 /vendor/szymach/c-pchart/src/BaseDraw.php(383): ceil('1.401.53')\n#1 /vendor/szymach/c-pchart/src/BaseDraw.php(342): CpChart\BaseDraw->processScale(0, '1.401.53', 2, Array, 0)\n#2 /vendor/szymach/c-pchart/src/Draw.php(2694): CpChart\BaseDraw->computeScale(0, '1.401.53', 2, Array, 0)\n#3 /plugins/ImageGraph/StaticGraph/GridGraph.php(177): CpChart\Draw->drawScale(Array)\n#4 /plugins/ImageGraph/StaticGraph/Evolution.php(24): Piwik\Plugins\ImageGraph\StaticGraph\GridGraph->initGridChart(true, 691053, false, true, true)\n#5 /plugins/ImageGraph/API.php(506): Piwik\Plugins\ImageGraph\StaticGraph\Evolution->renderGraph()\n#6 [internal function]: Piwik\Plugins\ImageGraph\API->get(1, 'day', '2022-10-03,2022...', 'Goals', 'get', 'evolution', 0, 'revenue', false, true, 984, 450, '27', '27', '1', 'ecommerceOrder', '3450A3,43a047', '222222', 'efefef', 'dcdcdc', false, '0', false, false)\n#7 /core/API/Proxy.php(244): call_user_func_array(Array, Array)\n#8 /core/Context.php(28): Piwik\API\Proxy->Piwik\API\{closure}()\n#9 /core/API/Proxy.php(335): Piwik\Context::executeWithQueryParameters(Array, Object(Closure))\n#10 /core/API/Request.php(267): Piwik\API\Proxy->call('\\Piwik\\Plugins\\...', 'get', Array)\n#11 /plugins/API/Controller.php(45): Piwik\API\Request->process()\n#12 [internal function]: Piwik\Plugins\API\Controller->index()\n#13 /core/FrontController.php(631): call_user_func_array(Array, Array)\n#14 /core/FrontController.php(169): Piwik\FrontController->doDispatch('API', false, Array)\n#15 /core/dispatch.php(32): Piwik\FrontController->dispatch()\n#16

URL: /index.php?module=API&method=ImageGraph.get&idSite=1&apiModule=Goals&apiAction=get&token_auth=XYZANONYMIZED&idGoal=ecommerceOrder&period=day&date=2022-10-03,2022-11-01&filter_sort_column=revenue&column=revenue&columns=revenue&language=en&width=984&height=450&fontSize=27&showMetricTitle=0&aliasedGraph=1&legendAppendMetric=0&backgroundColor=efefef&gridColor=dcdcdc&colors=3450A3%2C43a047&legendFontSize=27&cacherand=7280344

@tsteur tsteur added the Bug For errors / faults / flaws / inconsistencies etc. label Nov 2, 2022
@sgiehl
Copy link
Member

sgiehl commented Nov 9, 2022

This is yet another issue with numbers that a formatted to early. The ImageGraph fetches the numbers formatted from the database. Using those for calculations might result in failures.
There is actually some code, that tries to convert the formatted number back to something usable:

private static function parseOrdinateValue($ordinateValue)
{
$ordinateValue = @str_replace(',', '.', $ordinateValue);
// convert hh:mm:ss formatted time values to number of seconds
if (preg_match('/([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\.[0-9]{2})?)/', $ordinateValue, $matches)) {
$hour = $matches[1];
$min = $matches[2];
$sec = $matches[3];
$ordinateValue = ($hour * 3600) + ($min * 60) + $sec;
}
// OK, only numbers from here please (strip out currency sign)
$ordinateValue = preg_replace('/[^0-9.]/', '', $ordinateValue);
return $ordinateValue;
}

But this part actually might result in a invalid number. The error above seems to come from a revenue like 1,401.53 $. The code removes the currency and replaces the , with .. So the number being used i 1.401.53, which can't work.

I tried simply using the unformatted metrics for ImageGraph (see https://github.com/matomo-org/matomo/compare/m19940?expand=1), which fixes the problem above. But that means that most percent values, like conversion rate, are then not formatted at all and are used as their rate value, e.g. 0.15 instead of 15

This is actually a more general problem. Not sure if we already have a extra issue about that or only discussed that on various other ones. But the percentage metrics should actually not do any calculations while formatting. We might need to implement a way, that those metrics are always "calculated" automatically and formatted only when needed.

@sgiehl sgiehl added this to the For Prioritization milestone Nov 9, 2022
@justinvelluppillai
Copy link
Contributor

Do we now have an issue tracking the more general case @sgiehl, or could you please create one?

@tsteur
Copy link
Member Author

tsteur commented May 10, 2023

FYI this happened again a few times in GridGraph.php . Not BaseDraw.php

@michalkleiner
Copy link
Contributor

Thanks @tsteur, yep, that was raised in #20616 which I linked to this issue and marked as duplicate due to the same symptoms and that it will be resolved at the same time.

@tsteur
Copy link
Member Author

tsteur commented May 17, 2023

This has happened again in ceil(): Argument #1 ($num) must be of type int|float, string given","file":"/plugins\/ImageGraph\/StaticGraph\/GridGraph.php","line":137,"

@tsteur
Copy link
Member Author

tsteur commented May 21, 2023

This happened again: Error: {"message":"ceil(): Argument #1 ($num) must be of type int|float, string given","file":"/plugins\/ImageGraph\/StaticGraph\/GridGraph.php","line":137

@tsteur
Copy link
Member Author

tsteur commented May 28, 2023

This happened again

@samjf
Copy link
Contributor

samjf commented Jun 13, 2023

I've seen multiple reports of this in cloud alerts/logs.
I've got a bit more info to add. Of all the alerts the majority are from the user agents (edited) Dalvik.../Android and Appcelerator Titanium/@"0.0.0" (iPhone...).
Also, as far as I can see they are mostly date ranges.

Payload example:

    "module": "API",
    "method": "ImageGraph.get",
    "idSite": "1",
    "apiModule": "Goals",
    "apiAction": "get",
    "token_auth": "...",
    "idGoal": "ecommerceOrder",
    "period": "day",
    "date": "2022-09-01,2022-11-01",
    "filter_sort_column": "revenue",
    "column": "revenue",
    "columns": "revenue",
    "language": "en",
    "width": "900",
    "height": "450",
    "fontSize": "25",
    "showMetricTitle": "0",
    "aliasedGraph": "1",
    "legendAppendMetric": "0",
    "backgroundColor": "efefef",
    "gridColor": "dcdcdc",
    "colors": "3450A3,43a047",
    "legendFontSize": "25",
    "cacherand": "1111111",
    "filter_limit": 100
}

@tsteur
Copy link
Member Author

tsteur commented Jun 22, 2023

This happened again

2 similar comments
@tsteur
Copy link
Member Author

tsteur commented Jun 30, 2023

This happened again

@tsteur
Copy link
Member Author

tsteur commented Jul 30, 2023

This happened again

@tsteur
Copy link
Member Author

tsteur commented Aug 7, 2023

This is still happening regularly

@tsteur
Copy link
Member Author

tsteur commented Sep 3, 2023

This is still happening

@tsteur
Copy link
Member Author

tsteur commented Oct 31, 2023

This error is still happening in Matomo 5.
Users are still running into this bug. Also happened Oct 24th and Oct 23rd and Oct 21st.

Note that below is about GridGraph.php and not BaseDraw.php. I comment them in here as my other specific issue for this in #20616 was closed with a reference being a duplicate.

Can we have a fix for this some time? cc @Stan-vw

Error: {"message":"ceil(): Argument #1 ($num) must be of type int|float, string given","file":"/plugins/ImageGraph/StaticGraph/GridGraph.php","line":137,"request_id":"4d5dd","backtrace":" on /plugins/ImageGraph/StaticGraph/GridGraph.php(137)\n#0 /plugins/ImageGraph/StaticGraph/GridGraph.php(137): ceil('8.841.60')\n#1 /plugins/ImageGraph/StaticGraph/Evolution.php(24): Piwik\Plugins\ImageGraph\StaticGraph\GridGraph->initGridChart(true, 691053, false, true, true)\n#2 /plugins/ImageGraph/API.php(504): Piwik\Plugins\ImageGraph\StaticGraph\Evolution->renderGraph()\n#3 [internal function]: Piwik\Plugins\ImageGraph\API->get(5, 'day', 'last7', 'Goals', 'get', 'evolution', 0, 'revenue', false, true, 996, 394, '24', '24', '1', 'ecommerceOrder', '3450A3,43a047', '222222', 'efefef', 'dcdcdc', false, '0', false, false)\n#4 /core/API/Proxy.php(255): call_user_func_array(Array, Array)\n#5 /core/Context.php(28): Piwik\API\Proxy->Piwik\API\{closure}()\n#6 /core/API/Proxy.php(346): Piwik\Context::executeWithQueryParameters(Array, Object(Closure))\n#7 /core/API/Request.php(272): Piwik\API\Proxy->call('\\Piwik\\Plugins\\...', 'get', Array)\n#8 /plugins/API/Controller.php(45): Piwik\API\Request->process()\n#9 [internal function]: Piwik\Plugins\API\Controller->index()\n#10 /core/FrontController.php(637): call_user_func_array(Array, Array)\n#11 /core/FrontController.php(169): Piwik\FrontController->doDispatch('API', false, Array)\n#12 /core/dispatch.php(32): Piwik\FrontController->dispatch()\n#13 /index.php(25): require_once('/c...')\n#14 {main}","safemode_backtrace":"#0 [internal function]: Piwik\Plugins\Cloud\Controller->safemode(Array)\n#1 /core/FrontController.php(637): call_user_func_array(Array, Array)\n#2 /core/FrontController.php(16

@tsteur
Copy link
Member Author

tsteur commented Dec 5, 2023

This is still happening multiple times per week for customers

@michalkleiner
Copy link
Contributor

michalkleiner commented Dec 5, 2023

Looking at GridGraph L137, we use ceil method there. That can take strings as long as they can be converted to numbers, so the issue here would be that we have a non-numeric string in the data, or a number that has been double sanitised or wrongly encoded/decoded and ended up e.g. with two decimal dots or so.

@Stan-vw
Copy link
Contributor

Stan-vw commented Dec 5, 2023

I understand from the team that it's blocked by #20701 which isn't a quick fix

@tsteur
Copy link
Member Author

tsteur commented Jan 6, 2024

This just happened again quite a few times:

Error: {"message":"ceil(): Argument #1 ($num) must be of type int|float, string given","file":"/plugins/ImageGraph/StaticGraph/GridGraph.php","line":137,"request_id":"f27fd","backtrace":" on /plugins/ImageGraph/StaticGraph/GridGraph.php(137)\n#0 /plugins/ImageGraph/StaticGraph/GridGraph.php(137): ceil('0.0.0.0')

@jalavosus
Copy link

I also have issues with this bug. Matomo regularly shows revenue from a product which is priced at ex. $7,500 (with that EXACT formatting) as having made $7. Many, many currencies and number representations around the globe use commas as a visual separator (and specifically not as a decimal separator), and it's mildly atrocious that it hasn't been fixed in so long.

This is an easy fix for an organization with multiple engineers - in fact, it's a problem I've had to solve for basic technical interview rounds. It has been a bug for far too long.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc.
Projects
None yet
Development

No branches or pull requests

7 participants