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

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

Open
os-nikita opened this issue May 18, 2022 · 6 comments
Open

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

os-nikita opened this issue May 18, 2022 · 6 comments
Labels
solution-request Request a solution be created for an exception

Comments

@os-nikita
Copy link

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.

@josephmancuso josephmancuso added the solution-request Request a solution be created for an exception label May 18, 2022
@girardinsamuel
Copy link
Contributor

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

@josephmancuso
Copy link
Member

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
Copy link
Member

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
Copy link
Author

os-nikita commented Jun 6, 2022

@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
Copy link
Member

josephmancuso commented Jun 6, 2022

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.

@josephmancuso josephmancuso reopened this Jun 6, 2022
@girardinsamuel
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solution-request Request a solution be created for an exception
Projects
None yet
Development

No branches or pull requests

3 participants