Skip to content
Open
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
4 changes: 2 additions & 2 deletions geonode_mapstore_client/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def metadata(request, pk, template="geonode-mapstore-client/metadata.html"):
lang = get_language_from_request(request)[:2]
schema = metadata_manager.get_schema(lang)
resource = ResourceBase.objects.get(pk=pk)
schema_instance = metadata_manager.build_schema_instance(resource)
schema_instance = metadata_manager.build_schema_instance(resource, lang)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

While passing lang to build_schema_instance is correct, the way lang is obtained on line 58 is unsafe. get_language_from_request can return None, and None[:2] will raise a TypeError, causing an unhandled exception (500 error). It would be safer to handle this case by providing a fallback language.

I suggest changing line 58 to:

    lang = (get_language_from_request(request) or settings.LANGUAGE_CODE)[:2]

This ensures that lang always has a string value before slicing.


full_metadata = _parse_schema_instance(schema_instance, schema)
metadata = full_metadata['value']
Expand Down Expand Up @@ -233,4 +233,4 @@ def get(self, request, *args, **kwargs):

registry = RequestConfigurationRulesRegistry()
rules = registry.get_rules(request)
return Response(rules)
return Response(rules)