Skip to content

Commit

Permalink
Add fallback for unsupported Name attribute (#3017)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Jul 14, 2022
1 parent 8af2d3f commit e90c9d6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,11 @@ default if empty.
name(model::AbstractModel) = "An Abstract JuMP Model"

function name(model::Model)
ret = MOI.get(model, MOI.Name())
return isempty(ret) ? "A JuMP Model" : ret
if MOI.supports(backend(model), MOI.Name())
ret = MOI.get(model, MOI.Name())
return isempty(ret) ? "A JuMP Model" : ret
end
return "A JuMP Model"
end

"""
Expand Down
9 changes: 9 additions & 0 deletions test/print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,15 @@ function test_print_IJulia_with_math_operators()
return
end

struct _UnsupportedNameOptimizer <: MOI.AbstractOptimizer end
MOI.is_empty(::_UnsupportedNameOptimizer) = true

function test_Name_direct_mode()
model = direct_model(_UnsupportedNameOptimizer())
@test name(model) == "A JuMP Model"
return
end

end

TestPrint.runtests()

0 comments on commit e90c9d6

Please sign in to comment.