Fix show(::DecisionModel) by extending IOM._show_method instead of shadowing it#142
Merged
Conversation
…adowing it show(::AbstractOptimizationModel) (defined in IOM) delegates to _show_method(io, model.template, ...). POM defines that template method in utils/print.jl, but never imported _show_method from IOM, so POM created a separate PowerOperationsModels._show_method function. The template method was attached to POM's copy while IOM's delegation calls IOM's copy, which has no method for PowerOperationsProblemTemplate. Result: printing any DecisionModel threw MethodError (show on a bare template happened to work because POM's own show methods resolve to POM's local function). Add _show_method to the IOM import list so POM's definition extends the shared function. Add a regression test that show(::DecisionModel) renders the template for both the text/plain and text/html paths.
jd-lara
approved these changes
Jun 24, 2026
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.
Problem
Printing any
DecisionModelthrows:Root cause
The print path for a
DecisionModelis:show(io, MIME"text/plain", ::DecisionModel)resolves to theAbstractOptimizationModelmethod in IOM (utils/print_pt_v3.jl)._show_method(io, model, :auto), which delegates to_show_method(io, model.template, backend).model.templateis aPowerOperationsProblemTemplate, whose_show_methodlives here insrc/utils/print.jl.The bug: POM never imported
_show_methodfrom IOM. So whenprint.jlwritesfunction _show_method(...), Julia created a brand-newPowerOperationsModels._show_methodseparate fromInfrastructureOptimizationModels._show_method. The template method was attached to POM's copy, but IOM's delegation calls IOM's copy — which has no method forPowerOperationsProblemTemplate→MethodError.showon a bare template worked on its own only because POM's ownshowmethods run in the POM module and resolve to the POM-local function. That asymmetry hid the bug until something printed a full model.Fix
Add
_show_methodto the existingimport InfrastructureOptimizationModels:block so POM's definition extends the shared function instead of shadowing it — the same pattern POM already uses for every other IOM function it specializes. One line; no change needed inprint.jlitself.Test
Adds a regression testset in
test/test_model_decision.jlthat constructs aDecisionModeland assertsshowrenders the template for both thetext/plainandtext/htmlpaths. This class of bug (cross-package function shadowing) is invisible until something prints, so the test guards both paths against future regressions.Verification
MethodErroragainst the delegation in IOM (identical in registered IOM 0.1.0 and the dev branch).show(model)now renders the Network Model and Device Models tables correctly.