MasoniteFramework / exceptionite

A Python Exception Library. Designed to make handling and displaying exceptions a cinch.
MIT License
124 stars 4 forks source link

"Model method does not exist" solution can be improved #52

Open os-nikita opened 2 years ago

os-nikita commented 2 years ago

If the model is brand new, hasn't been created yet (not model.is_created() == True), then trying to access a property on the model like if not user.picture: ... will result in this error. The solution offered can be confusing.

girardinsamuel commented 2 years ago

I am not sure to see what you mean. Could you post a code snippet so that I can reproduce the issue ? 🙏

josephmancuso commented 2 years ago

I think the way to replicate it is this:

Screen Shot 2022-06-05 at 5 30 37 PM

Results in this error

Screen Shot 2022-06-05 at 5 30 43 PM
josephmancuso commented 2 years ago

The error seems clear to me and i'm not sure what you find confusing about it. I'll reopen and fix if you can provide a solution that makes sense to you

os-nikita commented 2 years ago

@josephmancuso

Here's what I mean. This throws an exception, rather than rendering the home view:

image

It's not about a calling a method on a model. It's about the fact that the model hasn't been persisted yet and attempting to access an attribute/property (not a method), will throw this error.

If I change the above slightly to the following, the error isn't thrown. The email is returned:

image
josephmancuso commented 2 years ago

Ok so Ill add a possible solution like

Title: Model has not been created or retrieved

Solution: Make sure the model is correctly created or retrieved from the database before accessing attributes.

girardinsamuel commented 2 years ago

How you are going to differentiate a normal class from a model class ? Because it should be a solution for Masonite Model classes only... 🤔