diff --git a/arches/app/models/fields/i18n.py b/arches/app/models/fields/i18n.py index 69a229f5b33..509f277cbad 100644 --- a/arches/app/models/fields/i18n.py +++ b/arches/app/models/fields/i18n.py @@ -7,7 +7,7 @@ from django.db.models import JSONField from django.db.models.functions.comparison import Cast from django.db.models.sql import Query -from django.db.models.sql.compiler import SQLInsertCompiler +from django.db.models.sql.compiler import SQLInsertCompiler, SQLUpdateCompiler from django.db.models.sql.where import NothingNode from django.utils.translation import get_language @@ -63,8 +63,8 @@ def as_sql(self, compiler, connection): https://www.postgresql.org/docs/9.5/functions-json.html """ - if (self.value_is_primitive or self.value is None) and not isinstance( - compiler, SQLInsertCompiler + if (self.value_is_primitive or self.value is None) and isinstance( + compiler, SQLUpdateCompiler ): self.sql = "jsonb_set(" + self.attname + ", %s, %s)" params = (f"{{{self.lang}}}", json.dumps(self.value)) diff --git a/releases/8.0.0.md b/releases/8.0.0.md index eeb68108238..7ae404b31bd 100644 --- a/releases/8.0.0.md +++ b/releases/8.0.0.md @@ -25,6 +25,7 @@ Arches 8.0.0 Release Notes - Support more expressive plugin URLs [#11320](https://github.com/archesproject/arches/issues/11320) - Make node aliases not nullable [#10437](https://github.com/archesproject/arches/issues/10437) - Add alt text on image placeholder [#10455](https://github.com/archesproject/arches/issues/10455) +- Fix querying on related model's I18n_TextField [#11800](https://github.com/archesproject/arches/issues/11800) - Make failed login alert message dismissible [#11767](https://github.com/archesproject/arches/issues/11767) - Concepts API no longer responds with empty body for error conditions [#11519](https://github.com/archesproject/arches/issues/11519) - Removes sample index from new projects, updates test coverage behavior [#11591](https://github.com/archesproject/arches/issues/11519) diff --git a/tests/localization/field_tests.py b/tests/localization/field_tests.py index 20ee7f78a8f..39c31710b1c 100644 --- a/tests/localization/field_tests.py +++ b/tests/localization/field_tests.py @@ -8,6 +8,7 @@ I18n_JSON, I18n_JSONField, ) +from arches.app.models.models import Node from tests.base_test import ArchesTestCase from django.contrib.gis.db import models from django.utils import translation @@ -17,6 +18,11 @@ # python manage.py test tests.localization.field_tests --settings="tests.test_settings" +class I18nTextFieldFilterTests(ArchesTestCase): + def test_filter_related_model_i18n_text_field(self): + self.assertEqual(Node.objects.filter(graph__name__en="Graph Name").count(), 0) + + class Customi18nTextFieldTests(ArchesTestCase): @classmethod def setUpTestData(cls):