From e812f83e6d2806e1ccc7f02193ef93c92c8f9466 Mon Sep 17 00:00:00 2001 From: Jesse Vickery Date: Wed, 1 Oct 2025 16:02:21 +0000 Subject: [PATCH 1/3] feat(dev): non qualified res_url in SOLR; - Do not store qualified internal resource urls in SOLR records. --- ckan/lib/dictization/model_dictize.py | 5 ++++- ckan/lib/search/__init__.py | 4 +++- ckan/logic/action/get.py | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/ckan/lib/dictization/model_dictize.py b/ckan/lib/dictization/model_dictize.py index ef6bb071b84..8af6ec54df5 100644 --- a/ckan/lib/dictization/model_dictize.py +++ b/ckan/lib/dictization/model_dictize.py @@ -128,6 +128,9 @@ def resource_dictize(res: model.Resource, context: Context) -> dict[str, Any]: url = resource['url'] ## for_edit is only called at the times when the dataset is to be edited ## in the frontend. Without for_edit the whole qualified url is returned. + + # (canada fork only): do not store qualified URIs in SOLR. + # NOTE: super important for language domain support!!! if resource.get('url_type') == 'upload' and not context.get('for_edit'): url = url.rsplit('/')[-1] cleaned_name = munge.munge_filename(url) @@ -135,7 +138,7 @@ def resource_dictize(res: model.Resource, context: Context) -> dict[str, Any]: id=resource['package_id'], resource_id=res.id, filename=cleaned_name, - qualified=True) + qualified=False) # (canada fork only): unqualified elif resource['url'] and not urlsplit(url).scheme \ and not context.get('for_edit'): resource['url'] = u'http://' + url.lstrip('/') diff --git a/ckan/lib/search/__init__.py b/ckan/lib/search/__init__.py index c0b9954c697..7328221915b 100644 --- a/ckan/lib/search/__init__.py +++ b/ckan/lib/search/__init__.py @@ -208,7 +208,9 @@ def rebuild(package_id: Optional[str] = None, 'model': model, 'ignore_auth': True, 'validate': False, - 'use_cache': False + 'use_cache': False, + # (canada fork only): non-qualified res_url for lang domain support + 'for_index': True, }) if package_id: diff --git a/ckan/logic/action/get.py b/ckan/logic/action/get.py index 272a401e9f5..c507dfd3a15 100644 --- a/ckan/logic/action/get.py +++ b/ckan/logic/action/get.py @@ -14,6 +14,9 @@ import sqlalchemy from sqlalchemy import text +# (canada fork only): non-qualified res_url for lang domain support +from flask import request + import ckan import ckan.lib.dictization @@ -1093,6 +1096,19 @@ def package_show(context: Context, data_dict: DataDict) -> ActionResult.PackageS for item in plugins.PluginImplementations(plugins.IPackageController): item.after_dataset_show(context, package_dict) + # (canada fork only): non-qualified res_url for lang domain support + if not context.get('for_index'): + try: + current_domain = request.host_url.rstrip('/') + except RuntimeError: + current_domain = config['ckan.site_url'].rstrip('/') + for res_dict in package_dict['resources']: + if( + res_dict.get('url_type') == 'upload' and + res_dict.get('url', '').startswith('/') + ): + res_dict['url'] = current_domain + res_dict['url'] + return package_dict From 75f0459ecd843dbfd72c5b702669bde211de2e68 Mon Sep 17 00:00:00 2001 From: Jesse Vickery Date: Wed, 1 Oct 2025 18:20:46 +0000 Subject: [PATCH 2/3] feat(dev): non qualified res_url in SOLR; - Do not store qualified internal resource urls in SOLR records. --- ckan/lib/search/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ckan/lib/search/__init__.py b/ckan/lib/search/__init__.py index 7328221915b..6848f1ecb42 100644 --- a/ckan/lib/search/__init__.py +++ b/ckan/lib/search/__init__.py @@ -175,7 +175,9 @@ def notify(self, entity: Any, operation: str) -> None: 'model': model, 'ignore_auth': True, 'validate': False, - 'use_cache': False + 'use_cache': False, + # (canada fork only): non-qualified res_url for lang domain support + 'for_index': True, }), {'id': entity.id}), operation) elif operation == domain_object.DomainObjectOperation.deleted: dispatch_by_operation(entity.__class__.__name__, From bacfb51e88cc1d3b4dbd47c432b68ebc256eb33a Mon Sep 17 00:00:00 2001 From: Jesse Vickery Date: Wed, 1 Oct 2025 18:27:20 +0000 Subject: [PATCH 3/3] feat(misc): changelog; - Added change log file. --- changes/211.canada.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/211.canada.feature diff --git a/changes/211.canada.feature b/changes/211.canada.feature new file mode 100644 index 00000000000..ac9f1e18e1a --- /dev/null +++ b/changes/211.canada.feature @@ -0,0 +1 @@ +Resource URLs are now only stored as relative paths in SOLR. The request hostname is prepended during `package_show` \ No newline at end of file