Fix resource operations corrupting package-level multilang translations#49
Merged
Merged
Conversation
Agent-Logs-Url: https://github.com/geosolutions-it/ckanext-multilang/sessions/fb2d3167-a4a9-47d1-b9fb-820ecf6c7cee Co-authored-by: etj <717359+etj@users.noreply.github.com>
…aset_update) Agent-Logs-Url: https://github.com/geosolutions-it/ckanext-multilang/sessions/fb2d3167-a4a9-47d1-b9fb-820ecf6c7cee Co-authored-by: etj <717359+etj@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix resource updates causing package-level translation corruption
Fix resource operations corrupting package-level multilang translations
May 4, 2026
There was a problem hiding this comment.
Pull request overview
Fixes a multilang regression in the CKAN extension where resource CRUD operations could overwrite package-level translations with stale package-table values during CKAN’s internal package_update flow.
Changes:
- Added a resource-operation context flag so
after_dataset_updateskips package multilang writes during resource create/update/delete. - Cleared that flag in the corresponding resource after-hooks.
- Added regression-oriented tests for flag lifecycle behavior and simulated resource hook flows.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
ckanext/multilang/plugin.py |
Adds the context-flag guard around package multilang updates during resource operations. |
ckanext/multilang/tests/test_resource_update_fix.py |
Adds unit tests covering flag set/clear behavior and simulated create/update/delete sequences. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+99
to
+103
| with patch('ckanext.multilang.plugin.helpers.getLanguage', return_value='de'), \ | ||
| patch('ckanext.multilang.plugin.after_update_dataset', | ||
| side_effect=fake_after_dataset_update), \ | ||
| patch('ckanext.multilang.plugin.after_update_resource'): | ||
|
|
Comment on lines
+128
to
+131
| with patch('ckanext.multilang.plugin.helpers.getLanguage', return_value='de'), \ | ||
| patch('ckanext.multilang.plugin.after_update_dataset', | ||
| side_effect=lambda *a: pkg_update_calls.append(a)), \ | ||
| patch('ckanext.multilang.plugin.after_create_resource'): |
Comment on lines
+168
to
+173
| """after_resource_update must clear the flag regardless of language.""" | ||
| plugin = self._make_plugin() | ||
| context = {plugin._RESOURCE_OP_FLAG: True} | ||
| with patch('ckanext.multilang.plugin.helpers.getLanguage', return_value=None): | ||
| plugin.after_resource_update(context, {}) | ||
| self.assertNotIn(plugin._RESOURCE_OP_FLAG, context) |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a resource is created, updated, or deleted, CKAN internally calls
package_update, triggeringafter_dataset_updatewith apkg_dictsourced from the corepackagetable — which holds the last-saved language's text, not the current session language's translation. The multilang extension blindly overwrites the current-languagepackage_multilangentries with this stale data.Changes
ckanext/multilang/plugin.pybefore_resource_create/update/deletehooks that set a'__multilang_skip_pkg_update'flag on the shared CKANcontextdict before the internalpackage_updateis calledafter_dataset_updatenow skips the package multilang update when this flag is presentafter_resource_create/updateand newafter_resource_deleteclear the flag after the resource operation completesThe flag is passed cleanly through the context (the same dict CKAN threads through
before_resource_*→package_update→after_dataset_update→after_resource_*), requiring no thread-local storage.ckanext/multilang/tests/test_resource_update_fix.py