Skip to content
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

Fix querying on related model's I18n_TextField #11800 #11801

Open
wants to merge 1 commit into
base: dev/8.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions arches/app/models/fields/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Comment on lines -66 to +67
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a filter() call, this was coming in as just SQLCompiler.

):
self.sql = "jsonb_set(" + self.attname + ", %s, %s)"
params = (f"{{{self.lang}}}", json.dumps(self.value))
Expand Down
1 change: 1 addition & 0 deletions releases/8.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions tests/localization/field_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Comment on lines +22 to +23
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other test classes in this file use custom models, but they didn't have foreign keys set up, so it seemed simpler to just dogfood the real models. Open to changing this.



class Customi18nTextFieldTests(ArchesTestCase):
@classmethod
def setUpTestData(cls):
Expand Down