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

Bug: Postgresql API call delete use ->connID->affected_rows after Model::delete() got error #2918

Closed
samsonasik opened this issue May 2, 2020 · 2 comments
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@samsonasik
Copy link
Member

For example, I have the following code in resource controller:

public function delete($id = null)
{
    $delete = $this->model->delete($id);
    if ($delete->connID->affected_rows === 0)
    {
        return $this->failNotFound(sprintf(
            'product with id %d not found or already deleted',
            $id
        ));
    }

    return $this->respondDeleted(['id' => $id], 'product deleted');
}

The delete is working. But calling $delete->connID->affected_rows make error. For example, I run curl:

curl -i -X DELETE http://ci4.local/products/1

I got the following error:

TTP/1.1 500 Internal Server Error
Date: Sat, 02 May 2020 06:22:14 GMT
Server: Apache/2.4.41 (Unix) PHP/7.4.4
X-Powered-By: PHP/7.4.4
Cache-control: no-store, max-age=0, no-cache
Set-Cookie: firstTimeAccess=1; expires=Sat, 09-May-2020 06:22:14 GMT; Max-Age=604800; path=/
Content-Length: 4142
Connection: close
Content-Type: application/json; charset=UTF-8

<br />
<font size='1'><table class='xdebug-error xe-uncaught-exception' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Fatal error: Uncaught CodeIgniter\Format\Exceptions\FormatException: Failed to parse json string, error: "Type is not supported". in /Users/samsonasik/www/ci4/vendor/codeigniter4/codeigniter4/system/Format/Exceptions/FormatException.php on line <i>9</i></th></tr>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> CodeIgniter\Format\Exceptions\FormatException: Failed to parse json string, error: "Type is not supported". in /Users/samsonasik/www/ci4/vendor/codeigniter4/codeigniter4/system/Format/Exceptions/FormatException.php on line <i>9</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0642</td><td bgcolor='#eeeeec' align='right'>996592</td><td bgcolor='#eeeeec'>CodeIgniter\Debug\Exceptions->exceptionHandler(  )</td><td title='/Users/samsonasik/www/ci4/vendor/codeigniter4/codeigniter4/system/Debug/Exceptions.php' bgcolor='#eeeeec'>.../Exceptions.php<b>:</b>0</td></tr>
<tr><td bgcolor='#eeeeec' align='center'>2</td><td bgcolor='#eeeeec' align='center'>0.0655</td><td bgcolor='#eeeeec' align='right'>1008040</td><td bgcolor='#eeeeec'>CodeIgniter\Debug\Exceptions->respond(  )</td><td title='/Users/samsonasik/www/ci4/vendor/codeigniter4/codeigniter4/system/Debug/Exceptions.php' bgcolor='#eeeeec'>.../Exceptions.php<b>:</b>166</td></tr>
<tr><td bgcolor='#eeeeec' align='center'>3</td><td bgcolor='#eeeeec' align='center'>0.0655</td><td bgcolor='#eeeeec' align='right'>1008040</td><td bgcolor='#eeeeec'>CodeIgniter\Debug\Exceptions->format(  )</td><td title='/Users/samsonasik/www/ci4/vendor/codeigniter4/codeigniter4/system/API/ResponseTrait.php' bgcolor='#eeeeec'>.../ResponseTrait.php<b>:</b>134</td></tr>
<tr><td bgcolor='#eeeeec' align='center'>4</td><td bgcolor='#eeeeec' align='center'>0.0659</td><td bgcolor='#eeeeec' align='right'>1011720</td><td bgcolor='#eeeeec'>CodeIgniter\Format\JSONFormatter->format(  )</td><td title='/Users/samsonasik/www/ci4/vendor/codeigniter4/codeigniter4/system/API/ResponseTrait.php' bgcolor='#eeeeec'>.../ResponseTrait.php<b>:</b>414</td></tr>
</table></font>
{
    "title": "ErrorException",
    "type": "ErrorException",
    "code": 500,
    "message": "Uncaught CodeIgniter\\Format\\Exceptions\\FormatException: Failed to parse json string, error: \"Type is not supported\". in /Users/samsonasik/www/ci4/vendor/codeigniter4/codeigniter4/system/Format/Exceptions/FormatException.php:9\nStack trace:\n#0 /Users/samsonasik/www/ci4/vendor/codeigniter4/codeigniter4/system/Format/JSONFormatter.php(67): CodeIgniter\\Format\\Exceptions\\FormatException::forInvalidJSON('Type is not sup...')\n#1 /Users/samsonasik/www/ci4/vendor/codeigniter4/codeigniter4/system/API/ResponseTrait.php(414): CodeIgniter\\Format\\JSONFormatter->format(Array)\n#2 /Users/samsonasik/www/ci4/vendor/codeigniter4/codeigniter4/system/API/ResponseTrait.php(134): CodeIgniter\\Debug\\Exceptions->format(Array)\n#3 /Users/samsonasik/www/ci4/vendor/codeigniter4/codeigniter4/system/Debug/Exceptions.php(166): CodeIgniter\\Debug\\Exceptions->respond(Array, 500)\n#4 [internal function]: CodeIgniter\\Debug\\Exceptions->exceptionHandler(Object(ErrorException))\n#5 {main}\n  thrown",
    "file": "/Users/samsonasik/www/ci4/vendor/codeigniter4/codeigniter4/system/Format/Exceptions/FormatException.php",
    "line": 9,
    "trace": [
        {
            "function": "shutdownHandler",
            "class": "CodeIgniter\\Debug\\Exceptions",
            "type": "->",
            "args": []
        }
    ]
}

It is working fine in mysql.

CodeIgniter 4 version
4.0.3

Affected module(s)
Model, Database.

Expected behavior, and steps to reproduce if appropriate
Should be working.

Context

  • OS: macOS Sierra
  • Web server Apache
  • PHP version 7.4.4
@samsonasik samsonasik added the bug Verified issues on the current code behavior or pull requests that will fix them label May 2, 2020
@samsonasik
Copy link
Member Author

Just realize I should use affectedRows() from connection.

@samsonasik
Copy link
Member Author

For note: fixed with check:

if ($this->model->db->affectedRows() === 0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

No branches or pull requests

1 participant