-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Fixed #13296 Generating Custom Report Error #13297
Conversation
PR Summary
|
Wouldn't it make more sense to check for depreciation being valid/present in the report itself? |
Hi @snipe pretty hard to do If I cant download the report in the first place. Why would it spit those errors in any case? [2023-07-12 09:50:21] production.ERROR: Error: Call to a member function belongsTo() on null in /home/server/public_html/asset/app/Models/Asset.php:393 |
@snipe sorry, I'll leave you to work your magic :> |
@snipe I had not thought of that but I just test it and didn't work, I think it is because the call to We should never have an asset without a model, so I don't think adding a default model is disruptive or can be a potential risk on other places where this relation is needed. But do let me know if you think I need to adjust something here. |
@inietov so this would fx an error that happens in depreciation in the custom report when there is no model? |
@jayavman this definitely sounds like a data issue to me. Line 393 is the stuff in this method: public function depreciation()
{
return $this->model->belongsTo(\App\Models\Depreciation::class, 'depreciation_id');
} Which implies that there is a model an asset belongs to that is associated with an invalid depreciation or there is an invalid model to start with. |
hey @snipe anyway to find this easily? I have 14 000 assets? |
@snipe yes, it really should not happen that we end up with an asset having assigned an inexistent model (I had to edit the asset via the database to reproduce the error), but I see this fix as some of the conditions we sometimes add to models getters like precisely the depreciation one: So the system doesn't crash and users can fix their data if needed. |
That conditional should never fire though, since we check for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would take this - ideally, we should never allow people to delete a model that is still in use, but obviously it has happened with at least one user, and I would prefer to not break their reports if it has.
There is the possibility of returning a closure that creates a pseudo-model with attributes of your choosing - and we could return a 'name' of "Deleted Model" in that case (or trans('deleted_model')
or something else like that). That'd be nice too, but this, right now, seems to me to at least solve a real-world problem that a real user is actually having. (And, yes, I'd love to catch how people managed to do that, but in the end, we cannot prevent someone saying DELETE FROM models WHERE id=123
- which would cause something like this issue.
It's true that we don't do this elsewhere. But I still feel OK with it, I think.
@inietov what if we tried something like this instead: Current:Lines 391 to 394 in d26bc19
Proposed: public function depreciation()
{
return $this->hasOneThrough(\App\Models\Depreciation::class,\App\Models\AssetModel::class,'id','id','model_id','depreciation_id');
} I don't have data enough to test this, but when I use If this looks like a better option, @inietov and @uberbrady, I can put up a PR for testing. |
This looks more correct to me. We might even be able to get rid of all the |
…e model is busted Related: #13297 Signed-off-by: snipe <snipe@snipe.net>
If it leaves the model blank it works exactly as adding |
@jayavman I'd do a full custom report and look for blank fields where they shouldn't be. A blank asset model, for example. Since asset models are required, it would be weird to have a blank value there. Should be pretty easy in Excel to sort by that column and see what looks funny. |
Description
In some edge cases the Custom Report fails when trying to retrieve a belongsTo() relationship over asset models.
I added a check to evaluate if the model exists before trying to return that relationship, like in other relationships from the Asset model.Take 2: I added a default blank item in the asset->models relationship, so when it's called in asset->models->depreciation relationship it found one and doesn't fails. I can set a default model with, for example, a name attribute with
not found
as value or something like that, but I think a blank value is equally expressive in this case.Fixes #13296
Type of change
How Has This Been Tested?
Test Configuration: