Skip to content

Fix show(::DecisionModel) by extending IOM._show_method instead of shadowing it#142

Merged
jd-lara merged 1 commit into
mainfrom
rh/fix-decisionmodel-show
Jun 24, 2026
Merged

Fix show(::DecisionModel) by extending IOM._show_method instead of shadowing it#142
jd-lara merged 1 commit into
mainfrom
rh/fix-decisionmodel-show

Conversation

@rodrigomha

Copy link
Copy Markdown
Contributor

Problem

Printing any DecisionModel throws:

MethodError: no method matching _show_method(::IO, ::PowerOperationsProblemTemplate, ::Symbol)

Root cause

The print path for a DecisionModel is:

  1. show(io, MIME"text/plain", ::DecisionModel) resolves to the AbstractOptimizationModel method in IOM (utils/print_pt_v3.jl).
  2. That calls _show_method(io, model, :auto), which delegates to _show_method(io, model.template, backend).
  3. model.template is a PowerOperationsProblemTemplate, whose _show_method lives here in src/utils/print.jl.

The bug: POM never imported _show_method from IOM. So when print.jl writes function _show_method(...), Julia created a brand-new PowerOperationsModels._show_method separate from InfrastructureOptimizationModels._show_method. The template method was attached to POM's copy, but IOM's delegation calls IOM's copy — which has no method for PowerOperationsProblemTemplateMethodError.

show on a bare template worked on its own only because POM's own show methods 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_method to the existing import 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 in print.jl itself.

Test

Adds a regression testset in test/test_model_decision.jl that constructs a DecisionModel and asserts show renders the template for both the text/plain and text/html paths. This class of bug (cross-package function shadowing) is invisible until something prints, so the test guards both paths against future regressions.

Verification

  • Reproduced the MethodError against the delegation in IOM (identical in registered IOM 0.1.0 and the dev branch).
  • Verified the fix end-to-end against the live dev stack (psy6 / IS4 / dev IOM + this branch): show(model) now renders the Network Model and Device Models tables correctly.
  • Note: the new regression testset was not run in POM's standalone test environment locally because that env pins git-rev sibling sources (psy6 / IS4 / ac-ordc) whose resolution conflicts with the registered PowerSystems in my local registry — a pre-existing env-resolution issue unrelated to this change. CI exercises the test.

…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 jd-lara merged commit 5dbd8a6 into main Jun 24, 2026
1 of 6 checks passed
@jd-lara jd-lara deleted the rh/fix-decisionmodel-show branch June 24, 2026 00:31
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