Model no attribute 'id' after creating
See original GitHub issueDescribe the bug
Storing a new model does not allow to access the id attribute. Accessing in code after save() results in a
class model 'Category' has no attribute id
category.save()
request.session.flash('success', f'Saved: {category.id}')
return request.redirect_to('admin.category.table')
To Reproduce
create a simple store function:
from app.Category import Category
class CategoryController(Controller):
def store(self, request: Request):
category = Category()
category.name = request.input('name')
category.slug = request.input('slug')
category.description = request.input('description')
category.sorting = request.input('sorting')
category.save()
return category
Expected behavior What do you believe should be happening?
{
"id": 1,
"name": "test",
"slug": "test",
"description": "test",
"sorting": "1"
}
Actual behavior
{
"name": "test",
"slug": "test",
"description": "test",
"sorting": "1"
}
Screenshots or code snippets What database are you using?
- Type: SQLite 2.8.17
- Masonite ORM: masonite-orm==1.0.27
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
'model' object has no attribute 'id' - python - Stack Overflow
You've explicitly told Django that filmName is the primary key, so there is no separate ID. It's not usually a good idea to...
Read more >type object 'MyModel'' has no attribute 'id' - Google Groups
Exception Type: AttributeError at /support/helping/product/1/1. Exception Value: type object 'ProductModel' has no attribute 'id'. #----model
Read more >704 (AttributeError with non-standard primary key name)
... pk) AttributeError: 'Machine' object has no attribute 'id'. It does recognize it properly when generating SQL. "django-admin.py sql" gives: CREATE TABLE ...
Read more >Error on automatic primary key fields - model has no attribute ...
Based on the Typechecking models and queryset section of the tutorial, I do not expect error: "BlogPost" has no attribute "id" , and...
Read more >AttributeError: '_unknown' object has no attribute 'id'-- | Odoo
When I install the module the first time on clean database, i can create a record, but next times or if i uninstall...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@resmo releasing 1.0.29 now to fix this. Thanks for the report!
@Marlysson @resmo is correct, His code should be working as he is intending it to work. I think the issue is we are just missing a fill.