Page MenuHomePhabricator

Conduit update of int-fields fails
Closed, DuplicatePublic

Description

When trying to update a custom variable (type int), the request via curl (and also with json-serialized data POSTed) fails, while the manual call via /conduit/method/maniphest.edit/ works.

When I send [ { "type": "custom.jacob:test:field", "value": 5 } ] to "T286", this works, when I copy&paste the mentioned curl-call, curl http://phabricator.jacob.local/api/maniphest.edit -d api.token=api-token -d transactions[0][type]=custom.jacob%3Atest%3Afield -d transactions[0][value]=5 -d objectIdentifier=T286

{"result":null,"error_code":"ERR-CONDUIT-CORE","error_info":"Exception when processing transaction of type \"custom.jacob:test:field\": Error while reading \"value\": Expected integer, got something else."}

current versions:

arcanist: commit e78618ce225dd89d69c9f0a614c7edbb250af0d5
libphutil: commit b6f4e866fdb2c41de23c8e635c7803a09a44e9f4
phabricator: commit b88348a55e3588ea54c1514e6a28941c1e1dd0d0

Steps to reproduce

  • added custom integer-field in maniphest:

"jacob:test:field": { "name": "variable", "type": "int", "required": false, "search": false, "caption": "test-field" }

  • try to update via conduit/curl
[Fri Aug 26 09:03:34.937783 2016] [:error] [pid 9636] [client 127.0.0.1:37544] [2016-08-26 09:03:34] EXCEPTION: (PhutilProxyException) Exception when proces
sing transaction of type "custom.jacob.due.recurrence": Error while reading "value": Expected integer, got something else. {>} (Exception) Error while readi
ng "value": Expected integer, got something else. at [<phabricator>/src/applications/conduit/parametertype/ConduitParameterType.php:64]
[Fri Aug 26 09:03:34.939650 2016] [:error] [pid 9636] [client 127.0.0.1:37544] arcanist(head=stable, ref.master=2db40f995337, ref.stable=e78618ce225d), libj
acob(head=master, ref.master=1006f210e79a), phabricator(head=stable, ref.master=2ca269cb3113, ref.stable=b88348a55e35), phutil(head=stable, ref.master=ceca9
d1122ea, ref.stable=b6f4e866fdb2)
[Fri Aug 26 09:03:34.939711 2016] [:error] [pid 9636] [client 127.0.0.1:37544]   #0 <#3> ConduitParameterType::raiseValidationException(array, string, strin
g) called at [<phabricator>/src/applications/conduit/parametertype/ConduitIntParameterType.php:14]
[Fri Aug 26 09:03:34.939730 2016] [:error] [pid 9636] [client 127.0.0.1:37544]   #1 <#3> ConduitIntParameterType::getParameterValue(array, string) called at
 [<phabricator>/src/applications/conduit/parametertype/ConduitParameterType.php:38]
[Fri Aug 26 09:03:34.939745 2016] [:error] [pid 9636] [client 127.0.0.1:37544]   #2 <#3> ConduitParameterType::getValue(array, string) called at [<phabricat
or>/src/applications/transactions/editengine/PhabricatorEditEngine.php:1906]
[Fri Aug 26 09:03:34.939758 2016] [:error] [pid 9636] [client 127.0.0.1:37544]   #3 <#2> PhabricatorEditEngine::getConduitTransactions(ConduitAPIRequest, ar
ray, ManiphestTransaction) called at [<phabricator>/src/applications/transactions/editengine/PhabricatorEditEngine.php:1801]
[Fri Aug 26 09:03:34.939773 2016] [:error] [pid 9636] [client 127.0.0.1:37544]   #4 <#2> PhabricatorEditEngine::buildConduitResponse(ConduitAPIRequest) call
ed at [<phabricator>/src/applications/transactions/editengine/PhabricatorEditEngineAPIMethod.php:40]
[Fri Aug 26 09:03:34.939787 2016] [:error] [pid 9636] [client 127.0.0.1:37544]   #5 <#2> PhabricatorEditEngineAPIMethod::execute(ConduitAPIRequest) called at [<phabricator>/src/applications/conduit/method/ConduitAPIMethod.php:122]
[Fri Aug 26 09:03:34.939801 2016] [:error] [pid 9636] [client 127.0.0.1:37544]   #6 <#2> ConduitAPIMethod::executeMethod(ConduitAPIRequest) called at [<phabricator>/src/applications/conduit/call/ConduitCall.php:131]
[Fri Aug 26 09:03:34.939815 2016] [:error] [pid 9636] [client 127.0.0.1:37544]   #7 <#2> ConduitCall::executeMethod() called at [<phabricator>/src/applications/conduit/call/ConduitCall.php:81]
[Fri Aug 26 09:03:34.939829 2016] [:error] [pid 9636] [client 127.0.0.1:37544]   #8 <#2> ConduitCall::execute() called at [<phabricator>/src/applications/conduit/controller/PhabricatorConduitAPIController.php:81]
[Fri Aug 26 09:03:34.939885 2016] [:error] [pid 9636] [client 127.0.0.1:37544]   #9 phlog(PhutilProxyException) called at [<phabricator>/src/applications/conduit/controller/PhabricatorConduitAPIController.php:101]
[Fri Aug 26 09:03:34.939902 2016] [:error] [pid 9636] [client 127.0.0.1:37544]   #10 PhabricatorConduitAPIController::handleRequest(AphrontRequest) called at [<phabricator>/src/aphront/configuration/AphrontApplicationConfiguration.php:237]
[Fri Aug 26 09:03:34.939916 2016] [:error] [pid 9636] [client 127.0.0.1:37544]   #11 AphrontApplicationConfiguration::processRequest(AphrontRequest, PhutilDeferredLog, AphrontPHPHTTPSink, MultimeterControl) called at [<phabricator>/src/aphront/configuration/AphrontApplicationConfiguration.php:149]
[Fri Aug 26 09:03:34.939929 2016] [:error] [pid 9636] [client 127.0.0.1:37544]   #12 AphrontApplicationConfiguration::runHTTPRequest(AphrontPHPHTTPSink) called at [<phabricator>/webroot/index.php:17]

When digging into the code, we found /src/applications/conduit/parametertype/ConduitIntParameterType.php line 9 checking for is_int(), which would technically be correct, but in the aforementioned case, the parameter type of $value is string. When I change the check to is_numeric, the update works:

diff --git a/src/applications/conduit/parametertype/ConduitIntParameterType.php b/src/applications/conduit/parametertype/ConduitIntParameterType.php
index 54f66fd..47c4b58 100644
--- a/src/applications/conduit/parametertype/ConduitIntParameterType.php
+++ b/src/applications/conduit/parametertype/ConduitIntParameterType.php
@@ -6,7 +6,7 @@ final class ConduitIntParameterType
   protected function getParameterValue(array $request, $key) {
     $value = parent::getParameterValue($request, $key);

-    if (!is_int($value)) {
+    if (!is_numeric($value)) {
       $this->raiseValidationException(
         $request,
         $key,

This might not be the correct place, though; perhaps some sort of type-cast needs to be done when receiving the POST request?