Skip to content

[Fixes #14155] Fixes parameter order for mdict to set precedence from settings.PYCSW to pycsw_local defaults#14162

Open
cmotadev wants to merge 1 commit intoGeoNode:masterfrom
nds-cprm:master
Open

[Fixes #14155] Fixes parameter order for mdict to set precedence from settings.PYCSW to pycsw_local defaults#14162
cmotadev wants to merge 1 commit intoGeoNode:masterfrom
nds-cprm:master

Conversation

@cmotadev
Copy link
Copy Markdown
Contributor

Now it's possible to overwrite PyCSW parameterrs from settings and view mods in pyCSW GetCapabilites

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.

…ce from settings.PYCSW to pycsw_local defaults
@cla-bot cla-bot Bot added the cla-signed CLA Bot: community license agreement signed label Apr 23, 2026
@cmotadev cmotadev changed the title [Fixes #14155] Fixes parameter order for mdict to set precedence from [Fixes #14155] Fixes parameter order for mdict to set precedence from settings.PYCSW to pycsw_local defaults [Fixes #14155] Fixes parameter order for mdict to set precedence from settings.PYCSW to pycsw_local defaults Apr 23, 2026
Copy link
Copy Markdown
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 updates the configuration merging logic in pycsw_local.py and views.py to prioritize user settings over defaults. Feedback indicates that the current shallow merge approach leads to regressions by completely overwriting nested dictionaries like server, causing default values to be lost. Furthermore, the implementation risks mutating global constants. Suggestions have been provided to use a more robust merging strategy that preserves nested defaults and maintains immutability.

Comment on lines +127 to +131
mdict = dict(CONFIGURATION, **settings.PYCSW["CONFIGURATION"])
# if "server" in settings.PYCSW["CONFIGURATION"]:
# # override server system defaults with user specified directives
# # When swapping parameters from dict(), this if statement becomes useless
# mdict["server"].update(settings.PYCSW["CONFIGURATION"]["server"])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The current implementation performs a shallow merge, which causes the server dictionary to be completely replaced by the one in settings.PYCSW. This leads to a regression where default values defined in CONFIGURATION["server"] (such as domainquerytype) are lost if they are not explicitly redefined in the user settings.

Furthermore, the original code (now commented out) had a bug where it mutated the global CONFIGURATION constant because dict() only creates a shallow copy, and update() modifies the dictionary in place.

It is recommended to remove the commented-out code and use a merge strategy that preserves nested defaults and avoids mutating global constants.

Suggested change
mdict = dict(CONFIGURATION, **settings.PYCSW["CONFIGURATION"])
# if "server" in settings.PYCSW["CONFIGURATION"]:
# # override server system defaults with user specified directives
# # When swapping parameters from dict(), this if statement becomes useless
# mdict["server"].update(settings.PYCSW["CONFIGURATION"]["server"])
mdict = dict(CONFIGURATION, **settings.PYCSW["CONFIGURATION"])
if "server" in settings.PYCSW["CONFIGURATION"]:
mdict["server"] = dict(CONFIGURATION.get("server", {}), **settings.PYCSW["CONFIGURATION"]["server"])

return HttpResponseRedirect(settings.CATALOGUE["default"]["URL"])

mdict = dict(settings.PYCSW["CONFIGURATION"], **CONFIGURATION)
mdict = dict(CONFIGURATION, **settings.PYCSW["CONFIGURATION"])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This shallow merge will cause the server dictionary from settings.PYCSW to completely overwrite the defaults in CONFIGURATION. Additionally, since dict() creates a shallow copy, any subsequent modifications to nested dictionaries in mdict (for example, by config_updater on line 50) will inadvertently mutate the global CONFIGURATION object. It is safer to create a new dictionary for the nested server configuration to ensure defaults are preserved and the global state remains immutable.

Suggested change
mdict = dict(CONFIGURATION, **settings.PYCSW["CONFIGURATION"])
mdict = dict(CONFIGURATION, **settings.PYCSW["CONFIGURATION"])
if "server" in settings.PYCSW["CONFIGURATION"]:
mdict["server"] = dict(CONFIGURATION.get("server", {}), **settings.PYCSW["CONFIGURATION"]["server"])

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.

1 participant