-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Update project updated_time (#3810) #3814
Conversation
Update project.updated_date when included tasks are deleted, created or moved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for your contribution!
@dvkruchinin, hi, can you adjust our project tests to cover these changes? |
@jaesuny , thanks for the great contribution. Could you please add a line about the fix into CHANGELOG? |
cvat/apps/engine/views.py
Outdated
@@ -564,14 +564,36 @@ def retrieve(self, request, pk=None): | |||
raise serializers.ValidationError( | |||
"Unexpected action specified for the request") | |||
|
|||
def update(self, request, *args, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jaesuny , do we really need to have the method? Can we move all logic into perform_update which is called from update?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated!
cvat/apps/engine/views.py
Outdated
instance = serializer.save(owner=self.request.user) | ||
if instance.project: | ||
db_project = instance.project | ||
db_project.updated_date = timezone.now() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to fix in models.py instead. After that the field will be updated each time when the model is saved.
updated_date = models.DateTimeField(auto_now=True)
https://docs.djangoproject.com/en/3.2/ref/models/fields/#django.db.models.DateField.auto_now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated!
cvat/apps/engine/views.py
Outdated
@@ -564,14 +564,25 @@ def retrieve(self, request, pk=None): | |||
raise serializers.ValidationError( | |||
"Unexpected action specified for the request") | |||
|
|||
def perform_update(self, serializer): | |||
instance = self.get_object() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Serializer should already have the instance. Please use it: serializer.instance.
https://www.django-rest-framework.org/api-guide/serializers/#accessing-the-initial-data-and-instance
It is critical, because self.get_object will call check_object_permissions which ins't good here (it is already called in update method).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jaesuny , Thanks for your contribution! It is a great job!
I learned a lot thanks to you. |
@jaesuny , could you please merge develop (to fix most of problems with tests)? Also I see that there are some problems with Django tests. Looks like the PR breaks something.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jaesuny , thanks again. One test was failed, but it is an issue with our infra. We will address it soon. I will merge the PR now.
@dvkruchinin , could you please prepare a test for the issue? |
Motivation and context
Resolved #3810
Update
db_project.updated_date
when a task in the project is created, deleted or moved.How has this been tested?
Manually tested.
Checklist
develop
branchcvat-core, cvat-data and cvat-ui)
License
Feel free to contact the maintainers if that's a concern.