Repository: WeblateOrg/weblate

Issue:
Field last_change date is not updated in some cases
Field **last_changed** is not updated in following cases with **repro steps**:

_1st case:_
Somebody makes any changes to translations in git and pulls/rebase them in component (or any of maintenance functions), **last_changed** field is not updated. 

_2nd case:_
Somebody createы new component from file in git - **last_changed** is null. After that, somebody adds new translaiton in that component from weblate UI - **last_changed** is still null. 
Please, see attached screenshot for that case (you can see, that **total** field changed, but **last_changed** didn't)
![image](https://user-images.githubusercontent.com/17516013/133085977-6b9c6e1f-49fe-4a5a-ba9d-12fde7af2c7c.png)

I'm using this endpoint: https://docs.weblate.org/en/latest/api.html#get--api-translations-(string-project)-(string-component)-(string-language)-statistics-

**Expected behavior**
**last_changed** property is updated with every change. 
Also, since there is no property created_date, last_changed can be set after creating. 

Weblate version is 4.7.1 


Discussion:
This issue has been automatically marked as stale because there wasn’t any recent activity.

It will be closed soon if no further action occurs.

Thank you for your contributions!
That field currently indicates last change within Weblate, it does not reflect outside changes.
Seems, like there is no reason to expose that field, since it is meaningless for api user and reflects unknown internal processes  
This issue has been automatically marked as stale because there wasn’t any recent activity.

It will be closed soon if no further action occurs.

Thank you for your contributions!
It indicates when the translation was changed in Weblate. It's not meaningless for everybody if you don't have use for this information.
4.8.1 same problem.
We update texts via git (do some branch merging) and field is not updated :(
Field is updated exactly as intended - both `last_change` and `last_author` indicate last edit in Weblate. It behaves this way since ever.

See https://github.com/WeblateOrg/weblate/issues/5726 for related issue.
This issue has been automatically marked as stale because there wasn’t any recent activity.

It will be closed soon if no further action occurs.

Thank you for your contributions!

Resolving patch:
diff --git a/weblate/trans/models/change.py b/weblate/trans/models/change.py
--- a/weblate/trans/models/change.py
+++ b/weblate/trans/models/change.py
@@ -605,6 +605,10 @@ def save(self, *args, **kwargs):
             # Update cache for stats so that it does not have to hit
             # the database again
             self.translation.stats.last_change_cache = self
+            if self.translation.stats.is_loaded:
+                self.translation.stats.fetch_last_change()
+            self.translation.invalidate_cache()
+
             transaction.on_commit(self.update_cache_last_change)
 
     def get_absolute_url(self):
@@ -654,7 +658,7 @@ def store_last_change(cls, translation: Translation, change: Change | None):
         cache.set(cache_key, change.pk if change else 0, 180 * 86400)
 
     def is_last_content_change_storable(self):
-        return self.translation_id and self.action in self.ACTIONS_CONTENT
+        return self.translation_id
 
     def update_cache_last_change(self):
         self.store_last_change(self.translation, self)
diff --git a/weblate/trans/models/translation.py b/weblate/trans/models/translation.py
--- a/weblate/trans/models/translation.py
+++ b/weblate/trans/models/translation.py
@@ -81,9 +81,6 @@ def check_sync(
             translation.check_flags = flags
             translation.save(update_fields=["check_flags"])
         translation.check_sync(force, request=request, change=change)
-        if created:
-            Change.store_last_change(translation, None)
-
         return translation
 
 
diff --git a/weblate/utils/stats.py b/weblate/utils/stats.py
--- a/weblate/utils/stats.py
+++ b/weblate/utils/stats.py
@@ -172,6 +172,7 @@ def get_data(self):
 
         Used in stats endpoints.
         """
+        self.ensure_loaded()
         percents = [
             "translated_percent",
             "approved_percent",
@@ -688,7 +689,7 @@ def get_last_change_obj(self):
             except Change.DoesNotExist:
                 pass
         try:
-            last_change = self._object.change_set.content().order()[0]
+            last_change = self._object.change_set.order()[0]
         except IndexError:
             Change.store_last_change(self._object, None)
             return None


Test patch: