ktmud commented on a change in pull request #13020:
URL: https://github.com/apache/superset/pull/13020#discussion_r573195993



##########
File path: superset/models/helpers.py
##########
@@ -425,7 +425,19 @@ def changed_on_utc(self) -> str:
 
     @property
     def changed_on_humanized(self) -> str:
-        return humanize.naturaltime(datetime.now() - self.changed_on)
+        try:
+            from superset import conf
+            from flask_babel import get_locale
+            langs = conf.get("LANGUAGES", None)
+            locale = str(get_locale())
+
+            if "_" in locale:
+                humanize.i18n.activate(locale)
+            elif langs is not None:
+                humanize.i18n.activate("{}_{}".format(locale,
+                                                      
langs[locale]["flag"].upper()))

Review comment:
       It's only used here doesn't mean it will not be used elsewhere in the 
future. The pollution can happen when someone with another language came in and 
visit a page that used `humanize` without `activate` being called, they may see 
the global locale set by another use in another procedure, I.e.
   
   ```
   def func1:
      humanize.activate(...)
   
   def func2:
      no humanize activate
   
   user 1 (locale = zh) -> func1 -> zh
   user 2 (local = fr) -> func2 -> zh
   ```
   
   So it's safer if you always deactivate.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to