You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following example shows that the fallback behavior of TranslatedVirtualField.__get__() and TranslatedVirtualField.as_expression() is different, which is in my opinion not intuitive:
>>> with override("de"): print(blog.title_i18n)
foo
>>> with override("de"): print(Blog.objects.filter(id=blog.id).values("title_i18n"))
<MultilingualQuerySet [{'title_i18n': None}]>
This is because __get__() falls back to the original field value, whereas as_expression() only considers the languages in the fallback chain but not the original field value.
Adding the following before the Coalesce in as_expression() would fix that:
This would, in addition, also fix the error that you get in as_expression() when you specify an empty fallback chain by MODELTRANS_FALLBACK = {"default": ()}:
ValueError: Coalesce must take at least two expressions
The text was updated successfully, but these errors were encountered:
Assume you have the settings
and the following model instance:
The following example shows that the fallback behavior of
TranslatedVirtualField.__get__()
andTranslatedVirtualField.as_expression()
is different, which is in my opinion not intuitive:This is because
__get__()
falls back to the original field value, whereasas_expression()
only considers the languages in the fallback chain but not the original field value.Adding the following before the
Coalesce
inas_expression()
would fix that:This would, in addition, also fix the error that you get in
as_expression()
when you specify an empty fallback chain byMODELTRANS_FALLBACK = {"default": ()}
:The text was updated successfully, but these errors were encountered: