UserContributionRightsModel.put() should not be called from the service layer
#18,728 创建于 2023年8月2日
仓库指标
- 星标
- (5,292 个星标)
- PR 合并指标
- (平均合并 20天 19小时) (30 天内合并 71 个 PR)
描述
We are calling UserContributionRightsModel.put() from the user_service.py as per the below link.
This would create some inconsistent records in the UserContributionRightsModel as some fields (created_on, last_updated) are missed while creating models.
In general we should not be calling GAE datastore methods like put() directly from the service layer. All direct datastore put(), get() calls should be done from the storage layer and make use of methods on the base storage layer classes (see other storage model classes for examples).
What is expected from this issue:
- check whether UserContributionRightsModel is correctly setting created_on, last_updated when creating / updating the model instances.
- If it works as expected, we do not have to do anything.
- If it doesn't work as expected, we may have to investigate further. maybe this would be helpful: https://googleapis.dev/python/python-ndb/latest/model.html#google.cloud.ndb.model.DateTimeProperty._prepare_for_put. Maybe if we do not set auto_now, last_updated is not automatically set when updating an entity? In that case, created_on and last_updated would be same all the time.
Check how we do the same thing here: https://github.com/oppia/oppia/blob/develop/core/domain/suggestion_services.py#L771-L777