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 no attribute 'id' after creating #390
Comments
@resmo Which python version are you using to come with this sqlite version? |
@Marlysson that's a really good catch. That SQLite version is from 2005 ... |
@resmo, I'm trying reproduce that here and I've notice some litte problem. def store(self, request: Request):
category = Category()
# operations
category = category.save() # Assign back to variable.
return category With this you will be able to get the id of model. |
@Marlysson I confirm, assigning back to a var works. However, this assignment is totally not usual for an ORM, especially not how orator works https://orator-orm.com/docs/0.9/orm.html#insert-update-and-delete |
@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. if self.is_loaded():
result = builder.update(self.__dirty_attributes__)
else:
result = self.create(self.__dirty_attributes__, query=query)
self.observe_events(self, "saved")
self.fill(result) # <--- this is missing here. Assigns the result to the current model
return result |
@resmo releasing 1.0.29 now to fix this. Thanks for the report! |
Describe the bug
Storing a new model does not allow to access the
id
attribute. Accessing in code aftersave()
results in aclass model 'Category' has no attribute id
To Reproduce
create a simple store function:
Expected behavior
What do you believe should be happening?
Actual behavior
Screenshots or code snippets
What database are you using?
The text was updated successfully, but these errors were encountered: