dingo / dingo/api

Internal Requests returning inconsistent results

Open
#1,108 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
9.4k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

I am making internal requests to Dingo and experiencing inconsistent results. "Example-fied" code:

```
$response = $this->api->get('/api/v1/endpoint', [
'foreign_key_id' => $request->input('foreign_key_id'),
'include' => 'relationship_1,relationship_2.relationship_2_1',
]);
print_r($response);
```

This endpoint is setup to return a paginated collection of objects. "Example-fied" code:

```
// queries the model
$objects = $model->paginate(100);
return $this->response->paginator($objects, new $this->classTransformer());
```

In the vast majority of cases, I get the response I expect which is a Paginator Object:

```
Illuminate\\Pagination\\LengthAwarePaginator Object
(
[total:protected] => 1
[lastPage:protected] => 1
[items:protected] => Illuminate\\Database\\Eloquent\\Collection Object
(
[items:protected] => Array
(
[0] => App\\Endpoint Object
[snipped rest of result]
```

However, on some rare cases, what is returned instead is a Response Object wrapper around the Paginator Object:

```
Dingo\\Api\\Http\\Response Object
(
[exception] =>
[binding:protected] =>
[original] => Illuminate\\Pagination\\LengthAwarePaginator Object
(
[total:protected] => 1
[lastPage:protected] => 1
[items:protected] => Illuminate\\Database\\Eloquent\\Collection Object
(
[items:protected] => Array
(
[0] => App\\Endpoint Object
[snipped rest of result]
```

My code expects a Paginator object and loops through the result. So, whenever it doesn't get a Paginator, users experience a "whoops something went wrong" page and the error log shows a `ErrorException: Trying to get property of non-object` type error. In every report of the error page, refreshing the page immediately "fixes" the problem. Meaning, in other words, that **the exact same query on the exact same data a few seconds later returns the expected response**.

There's nothing in my code to switch between these types of responses. The same code querying the same tables with the same underlying data seems to randomly (and rarely) return a different type of response.

I've searched the reported issues here already and didn't see anything similar so I'm reporting this in the hopes that folks more experienced with Dingo can identify what the underlying issue is.

Thanks! :)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.