Double sum over two identical variables

I am trying to implement a mathematical model in JuMP but cant seem to figure out how i should write this constraint because i needs to be in both A and P

@constraint(m,
[(i,j) in data.A, i in data.P],
sum(xs[(i, j), s] for s in data.Si[i]) - x[(i, j)] == 0
)

the error i get is : LoadError: syntax: local variable name “i” conflicts with an argument
how can i make this constraint work?

JuMP’s @constraint macro with multiple index declarations like [(i,j) in data.A, i in data.P] treats i as a macro argument in the outer scope, causing a name conflict when i is also used inside the generator expression.

Use a single set for iteration that combines both conditions, ensuring i is only a local generator variable:

@constraint(m, [(i,j) in data.A if i in data.P],
    sum(xs[(i, j), s] for s in data.Si[i]) - x[(i, j)] == 0
)

Additionally, this is not a “double sum” (as written in the title).


If (i, j) represents an arc and i is a node, you may want to read

And also https://github.com/jump-dev/JuMP.jl/pull/3810#issuecomment-3783782727