Skip to content

Fix module-level dict mutation in galaxy-config-init#10

Closed
Copilot wants to merge 2 commits intodevfrom
copilot/fix-upstream-pr-21049-issue
Closed

Fix module-level dict mutation in galaxy-config-init#10
Copilot wants to merge 2 commits intodevfrom
copilot/fix-upstream-pr-21049-issue

Conversation

Copy link
Copy Markdown

Copilot AI commented Oct 30, 2025

PR galaxyproject#21049 introduced a bug where main() mutates the module-level GALAXY_CONFIG_SUBSTITUTIONS dictionary when --db-conn is provided, causing side effects across function calls.

Changes

  • Create local copy of GALAXY_CONFIG_SUBSTITUTIONS before modification
  • Pass substitutions dict as parameter to _handle_galaxy_yml()
  • Use local copy instead of module constant
# Before
def main(argv=None):
    # ...
    if args.db_conn:
        GALAXY_CONFIG_SUBSTITUTIONS["  #database_connection: null"] = "..."  # Mutates module state
    _handle_galaxy_yml(args, config_dir, data_dir)

# After  
def main(argv=None):
    # ...
    substitutions = GALAXY_CONFIG_SUBSTITUTIONS.copy()
    if args.db_conn:
        substitutions["  #database_connection: null"] = "..."  # Modifies local copy
    _handle_galaxy_yml(args, config_dir, data_dir, substitutions)

Fixes architectural issue while preserving functionality.

Original prompt

PR https://github.com/galaxyproject/galaxy/pull/21049/files in the upstream repository is wrong. The fix is in this comment usegalaxy-eu/infrastructure-playbook#1693.

Create a branch in kysrpex/galaxyproject-galaxy that fixes the issue. I will open a PR manually using that branch later in galaxyproject/galaxy.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

The previous implementation modified the module-level GALAXY_CONFIG_SUBSTITUTIONS
dictionary inside the main() function when --db-conn was provided. This is
poor practice because:
1. It has side effects on module state
2. Makes the function impure and harder to test
3. Could cause issues if the function is called multiple times

The fix creates a local copy of the dictionary before modifying it, preventing
mutation of the module-level constant.

Co-authored-by: kysrpex <43052541+kysrpex@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue in upstream PR 21049 based on feedback Fix module-level dict mutation in galaxy-config-init Oct 30, 2025
Copilot AI requested a review from domgz October 30, 2025 13:33
@domgz domgz closed this Oct 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants