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

When trying to upload a gift image, I get a stack trace in my log, and the image doesn't upload. #5516

Closed
JonTheNiceGuy opened this issue Sep 17, 2021 · 4 comments · Fixed by #5664

Comments

@JonTheNiceGuy
Copy link

Describe the bug
Click on Gifts Given -> Add a gift, provide the item's name, select "Photo (optional)", click on "upload" and select an image, click "add". No image listed, and the following stack trace provided in data/logs/laravel-yyyy-mm-dd.log. Note that this is running in Docker, with a docker-compose file. I previously enabled "Redis", but seeing other issues similar to this, I removed redis from the file, and did docker-compose down ; docker-compose up -d - the issue still occurs.

[2021-09-17 23:48:09] production.ERROR: Attempt to read property "id" on null {"userId":1,"exception":"[object] (ErrorException(code: 0): Attempt to read property \"id\" on null at /var/www/html/vendor/laravel/framework/src/Illuminate/Http/Resources/DelegatesToResource.php:140)
[stacktrace]
#0 /var/www/html/vendor/laravel/framework/src/Illuminate/Http/Resources/DelegatesToResource.php(140): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(2, 'Attempt to read...', '/var/www/html/v...', 140)
#1 /var/www/html/app/Http/Resources/Gift/Gift.php(24): Illuminate\\Http\\Resources\\Json\\JsonResource->__get('id')
#2 /var/www/html/vendor/laravel/framework/src/Illuminate/Http/Resources/Json/JsonResource.php(95): App\\Http\\Resources\\Gift\\Gift->toArray(Object(Illuminate\\Http\\Request))
#3 /var/www/html/vendor/laravel/framework/src/Illuminate/Http/Resources/Json/ResourceResponse.php(39): Illuminate\\Http\\Resources\\Json\\JsonResource->resolve(Object(Illuminate\\Http\\Request))
#4 /var/www/html/vendor/laravel/framework/src/Illuminate/Http/Resources/Json/JsonResource.php(221): Illuminate\\Http\\Resources\\Json\\ResourceResponse->toResponse(Object(Illuminate\\Http\\Request))
#5 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(776): Illuminate\\Http\\Resources\\Json\\JsonResource->toResponse(Object(Illuminate\\Http\\Request))
#6 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(763): Illuminate\\Routing\\Router::toResponse(Object(Illuminate\\Http\\Request), Object(App\\Http\\Resources\\Gift\\Gift))
#7 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(695): Illuminate\\Routing\\Router->prepareResponse(Object(Illuminate\\Http\\Request), Object(App\\Http\\Resources\\Gift\\Gift))
#8 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#9 /var/www/html/app/Http/Controllers/Api/ApiController.php(80): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#10 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): App\\Http\\Controllers\\Api\\ApiController->App\\Http\\Controllers\\Api\\{closure}(Object(Illuminate\\Http\\Request), Object(Closure))
#11 /var/www/html/app/Http/Middleware/CheckLocale.php(28): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#12 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): App\\Http\\Middleware\\CheckLocale->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#13 /var/www/html/app/Http/Middleware/SentryContext.php(43): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#14 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): App\\Http\\Middleware\\SentryContext->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#15 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(127): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#16 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(103): Illuminate\\Routing\\Middleware\\ThrottleRequests->handleRequest(Object(Illuminate\\Http\\Request), Object(Closure), Array)
#17 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(55): Illuminate\\Routing\\Middleware\\ThrottleRequests->handleRequestUsingNamedLimiter(Object(Illuminate\\Http\\Request), Object(Closure), 'api', Object(Closure))
#18 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Routing\\Middleware\\ThrottleRequests->handle(Object(Illuminate\\Http\\Request), Object(Closure), 'api')
#19 /var/www/html/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php(44): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#20 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Auth\\Middleware\\Authenticate->handle(Object(Illuminate\\Http\\Request), Object(Closure), 'api')
#21 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#22 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(697): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#23 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(672): Illuminate\\Routing\\Router->runRouteWithinStack(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request))
#24 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(636): Illuminate\\Routing\\Router->runRoute(Object(Illuminate\\Http\\Request), Object(Illuminate\\Routing\\Route))
#25 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(625): Illuminate\\Routing\\Router->dispatchToRoute(Object(Illuminate\\Http\\Request))
#26 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(166): Illuminate\\Routing\\Router->dispatch(Object(Illuminate\\Http\\Request))
#27 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}(Object(Illuminate\\Http\\Request))
#28 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#29 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#30 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\ConvertEmptyStringsToNull->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#31 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#32 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(40): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#33 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\TrimStrings->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#34 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#35 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#36 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(86): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#37 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#38 /var/www/html/vendor/fideloper/proxy/src/TrustProxies.php(57): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#39 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Fideloper\\Proxy\\TrustProxies->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#40 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#41 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(141): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#42 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(110): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))
#43 /var/www/html/public/index.php(55): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
#44 {main}
"}
@nhymxu
Copy link

nhymxu commented Sep 21, 2021

Not using docker, but maybe you can try this way: #5257 (comment)

@particleflux
Copy link

particleflux commented Sep 27, 2021

Same issue on 3.2.0. Upon uploading a photo to a gift. (editing the gift actually, not creating). Stacktrace is the same though.

The photo is uploaded and connected to the gift though. Seems that just the generation of the /gifts/{gift}/photo/{photo} response is not working.

I think this is due to the fact that ApiGiftController https://github.com/monicahq/monica/blob/master/app/Http/Controllers/Api/ApiGiftController.php#L120 expects the AssociatePhotoToGift to return a gift object, though it does not.

Likely fixable like this:

--- a/app/Services/Contact/Gift/AssociatePhotoToGift.php
+++ b/app/Services/Contact/Gift/AssociatePhotoToGift.php
@@ -40,5 +40,7 @@ class AssociatePhotoToGift extends BaseService
         $gift->contact->throwInactive();
 
         $gift->photos()->syncWithoutDetaching([$photo->id]);
+
+        return $gift;
     }
 }

particleflux added a commit to particleflux/monica that referenced this issue Oct 1, 2021
Attempting to connect a photo to a gift, either an already existing one
or a freshly uploaded one, the AJAX call would return a 500 server
error. The error states of a `Attempt to read property "id" on null` in
`app\Http\Resources\Gift/Gift` line 24.

This is causes by attempting to use a void result of
`AssociatePhotoToGift` service in `ApiGiftController::associate()`
method.

Fixed by returning the actual `$gift` variable worked on, similar to the
related services.

This does fix the *stacktrace* in monicahq#5516, but not the issue itself. The
issue there is likely unrelated to the stacktrace.

Fixes monicahq#5397
particleflux added a commit to particleflux/monica that referenced this issue Oct 1, 2021
Attempting to connect a photo to a gift, either an already existing one
or a freshly uploaded one, the AJAX call would return a 500 server
error. The error states of a `Attempt to read property "id" on null` in
`app\Http\Resources\Gift/Gift` line 24.

This is causes by attempting to use a void result of
`AssociatePhotoToGift` service in `ApiGiftController::associate()`
method.

Fixed by returning the actual `$gift` variable worked on, similar to the
related services.

This does fix the *stacktrace* in monicahq#5516, but not the issue itself. The
issue there is likely unrelated to the stacktrace.

Fixes monicahq#5397
particleflux added a commit to particleflux/monica that referenced this issue Oct 1, 2021
Attempting to connect a photo to a gift, either an already existing one
or a freshly uploaded one, the AJAX call would return a 500 server
error. The error states of a `Attempt to read property "id" on null` in
`app\Http\Resources\Gift/Gift` line 24.

This is causes by attempting to use a void result of
`AssociatePhotoToGift` service in `ApiGiftController::associate()`
method.

Fixed by returning the actual `$gift` variable worked on, similar to the
related services.

This does fix the *stacktrace* in monicahq#5516, but not the issue itself. The
issue there is likely unrelated to the stacktrace.

Fixes monicahq#5397
@asbiin asbiin added the bug label Oct 2, 2021
asbiin pushed a commit that referenced this issue Oct 8, 2021
Attempting to connect a photo to a gift, either an already existing one
or a freshly uploaded one, the AJAX call would return a 500 server
error. The error states of a `Attempt to read property "id" on null` in
`app\Http\Resources\Gift/Gift` line 24.

This is causes by attempting to use a void result of
`AssociatePhotoToGift` service in `ApiGiftController::associate()`
method.

Fixed by returning the actual `$gift` variable worked on, similar to the
related services.

This does fix the *stacktrace* in #5516, but not the issue itself. The
issue there is likely unrelated to the stacktrace.

Fixes #5397
@github-actions
Copy link

🎉 This issue has been resolved in version 3.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions
Copy link

github-actions bot commented Nov 1, 2022

This issue has been automatically locked since there
has not been any recent activity after it was closed.
Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants