Skip to content

[Fixes #13971] Added optional query parameter to return all translated fields in resource APIs#13985

Merged
giohappy merged 6 commits intomasterfrom
ISSUE_13971
Feb 26, 2026
Merged

[Fixes #13971] Added optional query parameter to return all translated fields in resource APIs#13985
giohappy merged 6 commits intomasterfrom
ISSUE_13971

Conversation

@nrjadkry
Copy link
Contributor

@nrjadkry nrjadkry commented Feb 23, 2026

Fixes #13971

Checklist

Reviewing is a process done by project maintainers, mostly on a volunteer basis. We try to keep the overhead as small as possible and appreciate if you help us to do so by completing the following items. Feel free to ask in a comment if you have troubles with any of them.

For all pull requests:

  • Confirm you have read the contribution guidelines
  • You have sent a Contribution Licence Agreement (CLA) as necessary (not required for small changes, e.g., fixing typos in the documentation)
  • Make sure the first PR targets the master branch, eventual backports will be managed later. This can be ignored if the PR is fixing an issue that only happens in a specific branch, but not in newer ones.

The following are required only for core and extension modules (they are welcomed, but not required, for contrib modules):

  • There is a ticket in https://github.com/GeoNode/geonode/issues describing the issue/improvement/feature (a notable exemption is, changes not visible to end-users)
  • The issue connected to the PR must have Labels and Milestone assigned
  • PR for bug fixes and small new features are presented as a single commit
  • PR title must be in the form "[Fixes #<issue_number>] Title of the PR"
  • New unit tests have been added covering the changes, unless there is an explanation on why the tests are not necessary/implemented

Submitting the PR does not require you to check all items, but by the time it gets merged, they should be either satisfied or inapplicable.

@cla-bot cla-bot bot added the cla-signed CLA Bot: community license agreement signed label Feb 23, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @nrjadkry, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the GeoNode API by providing more flexibility in how multilingual data is exposed. It introduces a new query parameter that allows API consumers to retrieve all available translations for a resource's fields, rather than just the translation for the currently active language. This change improves data accessibility for applications requiring comprehensive multilingual content.

Highlights

  • New Query Parameter: Introduced an optional include_i18n query parameter for resource APIs, allowing users to request all translated fields for a resource.
  • API Response Modification: Modified the MultiLangOutputMixin to conditionally include all language versions of multilingual fields (e.g., title_en, title_fr) in the API response when include_i18n=true.
  • Multilingual Field Prefetching: Updated the MultiLangViewMixin to dynamically adjust database prefetching. When include_i18n=true, all multilingual fields are prefetched; otherwise, only fields for the current language are prefetched.
  • New Utility Function: Added a new utility function get_all_multilang_fields to programmatically retrieve a list of all possible multilingual field names configured in the system.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • geonode/metadata/multilang/serializers.py
    • Imported utils module for multilingual operations.
    • Modified to_representation method in MultiLangOutputMixin to support an include_i18n query parameter, allowing the API to return all translated fields.
    • Ensured that if include_i18n is false, only the current language's translation is returned.
  • geonode/metadata/multilang/utils.py
    • Introduced get_all_multilang_fields function to dynamically list all multilingual field names.
  • geonode/metadata/multilang/views.py
    • Modified get_queryset method in MultiLangViewMixin to respect the include_i18n query parameter.
    • Utilized the new get_all_multilang_fields function to prefetch all translated fields when include_i18n is enabled.
Activity
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces an optional include_i18n query parameter to resource APIs, allowing clients to request all translated fields for a resource instead of just the one for the current language. The changes correctly modify the queryset prefetching in MultiLangViewMixin and the serialization logic in MultiLangOutputMixin to support this new functionality.

My review includes suggestions to improve code quality:

  • Refactoring a new utility function to use a more Pythonic list comprehension.
  • Addressing code duplication for parsing the include_i18n parameter.
  • Improving performance and robustness in the serializer by avoiding repeated function calls within a loop and using a more reliable method for string parsing.

Comment on lines 21 to 22
base_field_name = sparse.name[:-13] # name_multilang_xx
lang_code = sparse.name[-2:]
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Using slicing with magic numbers (-13, -2) to parse the field name is fragile and hard to maintain. It assumes a fixed length for _multilang_ and the language code. A more robust approach would be to use rsplit('_multilang_', 1).

Suggested change
base_field_name = sparse.name[:-13] # name_multilang_xx
lang_code = sparse.name[-2:]
base_field_name, lang_code = sparse.name.rsplit('_multilang_', 1)

if not include_i18n:
representation[base_field_name] = sparse.value
else:
if lang_code == multi.get_language(request):
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Calling multi.get_language(request) inside a loop is inefficient as it will be executed for every translated field. It's better to call it once outside the loop, store the result in a variable, and use that variable here.

field_names = multi.get_multilang_fields_for_lang(lang)

request = getattr(self, "request", None)
include_i18n = request.query_params.get('include_i18n', 'false').lower() == 'true' if request else False
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This line for parsing the include_i18n query parameter is duplicated in geonode/metadata/multilang/serializers.py. To avoid code duplication (DRY principle), this logic should be extracted into a utility function in geonode/metadata/multilang/utils.py and called from both places.

@nrjadkry nrjadkry changed the title Add optional query parameter to return all translated fields in resource APIs [Fixes #13971] Added optional query parameter to return all translated fields in resource APIs Feb 23, 2026
@codecov
Copy link

codecov bot commented Feb 23, 2026

Codecov Report

❌ Patch coverage is 95.58824% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.32%. Comparing base (7f6c030) to head (4bc0e64).
⚠️ Report is 7 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #13985      +/-   ##
==========================================
+ Coverage   74.07%   74.32%   +0.25%     
==========================================
  Files         950      950              
  Lines       56826    57028     +202     
  Branches     7719     7732      +13     
==========================================
+ Hits        42093    42388     +295     
+ Misses      13044    12939     -105     
- Partials     1689     1701      +12     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nrjadkry nrjadkry requested review from etj and giohappy February 23, 2026 10:25
@giohappy giohappy requested review from giohappy and removed request for etj February 24, 2026 12:03
include_i18n = params.get("include_i18n", "false").lower() == "true" if request else False

if settings.MULTILANG_FIELDS and hasattr(instance, "_multilang_sparse_prefetch"):
for sparse in instance._multilang_sparse_prefetch:
Copy link
Contributor

Choose a reason for hiding this comment

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

using get_all_multilang_fields, you may loop on the returned fields instead of _multilang_sparse_prefetch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@etj
I’ve applied the suggested changes to get_all_multilang_fields (returning a dict) and updated the serializer as well

@giohappy giohappy requested review from etj and giohappy and removed request for giohappy February 24, 2026 16:14
Copy link
Contributor

@etj etj left a comment

Choose a reason for hiding this comment

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

Logic seems ok.
Pls add some tests for the new option.

@nrjadkry nrjadkry requested a review from etj February 26, 2026 10:13
@giohappy giohappy merged commit a595f66 into master Feb 26, 2026
33 of 35 checks passed
@giohappy giohappy deleted the ISSUE_13971 branch February 26, 2026 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed CLA Bot: community license agreement signed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add optional query parameter to return all translated fields in resource APIs

3 participants