Skip to content

Fix variable name-collision guard to match updated JuMP error message - #97

Merged
JulStraus merged 2 commits into
EnergyModelsX:mainfrom
magnuask:main
Aug 4, 2026
Merged

Fix variable name-collision guard to match updated JuMP error message#97
JulStraus merged 2 commits into
EnergyModelsX:mainfrom
magnuask:main

Conversation

@magnuask

Copy link
Copy Markdown
Contributor

Summary

Fixes #96 (#96).

The test suite fails during "General tests" and "Variable creation" with:

An object of name :sink_surplus is already registered in this model.

Root cause

When building variables for a type hierarchy, variables_elements (and variables_element_ext_data) in src/model.jl intentionally call variables_element for a supertype and then again for its subtypes. To avoid double-registration of the same JuMP variable name, the call is wrapped in a try/catch that silently continues when the raised ErrorException corresponds to an already-registered name.

The guard matched the error text against the hardcoded substrings:

  • "An object of name"
  • "is already attached to this model."

Newer JuMP (v1.31.1) changed the wording of the duplicate-registration error from "is already attached to this model." to "is already registered in this model.". Because the second substring no longer matches, the exception was re-thrown instead of swallowed, aborting the model build.

Changes

  • src/model.jl — the guards in variables_elements and variables_element_ext_data now accept both message variants for cross-version compatibility.
  • test/test_utils.jl — the "Variable creation" testset now asserts either message variant.
  • Bumped version 0.10.50.10.6 and added a NEWS.md entry.

Environment

  • Julia 1.12.3
  • JuMP 1.31.1

Related

@JulStraus
JulStraus merged commit f3db9dd into EnergyModelsX:main Aug 4, 2026
5 checks passed
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.

Test suite fails: variable name-collision guard no longer matches current JuMP error message

2 participants