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

Possible alternative to fixing #13296 - custom report failing when th… #13347

Merged
merged 1 commit into from
Jul 21, 2023

Conversation

snipe
Copy link
Owner

@snipe snipe commented Jul 20, 2023

Just PRing this up in case anyone wants it.

This is an alt approach to fixing #13296 (versus #13297)

…e model is busted

Related: #13297
Signed-off-by: snipe <snipe@snipe.net>
@what-the-diff
Copy link

what-the-diff bot commented Jul 20, 2023

PR Summary

  • Improvement in Relationship Method in Asset Model
    The PR introduces changes to the depreciation method in the Asset.php file, which is a part of the application's models. Instead of using belongsTo, it now uses the hasOneThrough method. This technical adjustment makes the code more efficient by reducing unnecessary database queries and thus helps our application run faster and more smoothly.

@inietov
Copy link
Collaborator

inietov commented Jul 20, 2023

Just tested this and the outcome is the same as with my fix. I think this works better for the reasons we already discuss, so I'm gonna proceed to close the other one.

@snipe
Copy link
Owner Author

snipe commented Jul 20, 2023

@jayavman are you able to pull this branch and tell me if this works?

@jayavman
Copy link

hey @snipe no it doesnt

@jayavman
Copy link

[2023-07-21 14:35:18] production.ERROR: Error: Call to a member function belongsTo() on null in /home/fredons/public_html/asset/app/Models/Asset.php:393
Stack trace:
#0 /home/fredons/public_html/asset/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php(539): App\Models\Asset->depreciation()
#1 /home/fredons/public_html/asset/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php(491): Illuminate\Database\Eloquent\Model->getRelationshipFromMethod('depreciation')
#2 /home/fredons/public_html/asset/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php(440): Illuminate\Database\Eloquent\Model->getRelationValue('depreciation')
#3 /home/fredons/public_html/asset/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(2029): Illuminate\Database\Eloquent\Model->getAttribute('depreciation')
#4 /home/fredons/public_html/asset/app/Http/Controllers/ReportsController.php(822): Illuminate\Database\Eloquent\Model->__get('depreciation')
#5 /home/fredons/public_html/asset/vendor/laravel/framework/src/Illuminate/Database/Concerns/BuildsQueries.php(51): App\Http\Controllers\ReportsController->App\Http\Controllers{closure}(Object(Illuminate\Database\Eloquent\Collection), 1)
#6 /home/fredons/public_html/asset/app/Http/Controllers/ReportsController.php(881): Illuminate\Database\Eloquent\Builder->chunk(20, Object(Closure))
#7 /home/fredons/public_html/asset/vendor/symfony/http-foundation/StreamedResponse.php(109): App\Http\Controllers\ReportsController->App\Http\Controllers{closure}()
#8 /home/fredons/public_html/asset/vendor/symfony/http-foundation/Response.php(394): Symfony\Component\HttpFoundation\StreamedResponse->sendContent()
#9 /home/fredons/public_html/asset/vendor/laravel/framework/src/Illuminate/Support/HigherOrderTapProxy.php(34): Symfony\Component\HttpFoundation\Response->send()
#10 /home/fredons/public_html/asset/public/index.php(53): Illuminate\Support\HigherOrderTapProxy->__call('send', Array)
#11 {main}
[2023-07-21 14:35:18] production.ERROR: Call to a member function belongsTo() on null {"userId":1,"exception":"[object] (Error(code: 0): Call to a member function belongsTo() on null at /home/fredons/public_html/asset/app/Models/Asset.php:393)
[stacktrace]
#0 /home/fredons/public_html/asset/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php(539): App\Models\Asset->depreciation()
#1 /home/fredons/public_html/asset/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php(491): Illuminate\Database\Eloquent\Model->getRelationshipFromMethod('depreciation')
#2 /home/fredons/public_html/asset/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php(440): Illuminate\Database\Eloquent\Model->getRelationValue('depreciation')
#3 /home/fredons/public_html/asset/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(2029): Illuminate\Database\Eloquent\Model->getAttribute('depreciation')
#4 /home/fredons/public_html/asset/app/Http/Controllers/ReportsController.php(822): Illuminate\Database\Eloquent\Model->__get('depreciation')
#5 /home/fredons/public_html/asset/vendor/laravel/framework/src/Illuminate/Database/Concerns/BuildsQueries.php(51): App\Http\Controllers\ReportsController->App\Http\Controllers\{closure}(Object(Illuminate\Database\Eloquent\Collection), 1)
#6 /home/fredons/public_html/asset/app/Http/Controllers/ReportsController.php(881): Illuminate\Database\Eloquent\Builder->chunk(20, Object(Closure))
#7 /home/fredons/public_html/asset/vendor/symfony/http-foundation/StreamedResponse.php(109): App\Http\Controllers\ReportsController->App\Http\Controllers\{closure}()
#8 /home/fredons/public_html/asset/vendor/symfony/http-foundation/Response.php(394): Symfony\Component\HttpFoundation\StreamedResponse->sendContent()
#9 /home/fredons/public_html/asset/vendor/laravel/framework/src/Illuminate/Support/HigherOrderTapProxy.php(34): Symfony\Component\HttpFoundation\Response->send()
#10 /home/fredons/public_html/asset/public/index.php(53): Illuminate\Support\HigherOrderTapProxy->__call('send', Array)
#11 {main}
"}

@inietov
Copy link
Collaborator

inietov commented Jul 21, 2023

@jayavman That should not happen with this branch, since belongsTo() is not used anymore. Are you sure that you pulled the correct branch?

@jayavman
Copy link

Snipe-IT version
v6.1.2 build 10938 (g32747cafd) just rain a php upgrade before testing it

@snipe
Copy link
Owner Author

snipe commented Jul 21, 2023

@jayavman you need to pull down this specific branch though, not master or develop. Running the upgrader will pull from master.

@snipe
Copy link
Owner Author

snipe commented Jul 21, 2023

You can try php upgrade fixes/custom_report_error_on_bad_model and it should pull this branch

@snipe snipe merged commit 39ea15a into develop Jul 21, 2023
@snipe snipe deleted the fixes/custom_report_error_on_bad_model branch July 21, 2023 14:18
@snipe
Copy link
Owner Author

snipe commented Jul 21, 2023

Never mind, you can try php upgrade.php develop - I merged this to the develop branch already

@jayavman
Copy link

Git is installed.
Switched to a new branch 'fixes/custom_report_error_on_bad_model'
Your configuration specifies to merge with the ref 'refs/heads/fixes/custom_report_error_on_bad_model'
from the remote, but no such ref was fetched.
-- No local changes to save
-- branch 'fixes/custom_report_error_on_bad_model' set up to track 'origin/fixes/custom_report_error_on_bad_model'.

@jayavman
Copy link

Just tested and it worked fine. The report came through

@snipe
Copy link
Owner Author

snipe commented Jul 21, 2023

Excellent - I’ll get that merged into master tonight or tomorrow. Thanks for testing!

@snipe
Copy link
Owner Author

snipe commented Jul 21, 2023

I’m still curious how your data got in that shape in the first place tho. @uberbrady and I were just discussing this over dinner. The only scenario we can come up with is:

  • Delete all of the assets from a model
  • Delete the model
  • Restore the asset
  • Asset is now associated with an invalid model

But honestly, we’re just not sure. If there’s anything you can think of that might explain how your asset(s) might have gotten donked, we’d love to see if we can prevent that in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants