Why are SetProperty and PropertyValue not working here?

I have a very simple graph, a loop:

x = Graph[{1, 2, 3, 4}, {1 <-> 2, 3 <-> 2, 3 <-> 4, 1 <-> 4},
EdgeWeight -> {1, 10, 30, 60}, VertexLabels -> "Name",
EdgeLabels -> "EdgeWeight"]

Now, I want to change the values of its EdgeWeights. First, let's make sure I can even fetch them:

In:= PropertyValue[x, EdgeWeight]

Out= {1, 10, 30, 60}

Yay! Now let's try and change them:

In:= PropertyValue[x, EdgeWeight] = {20, 49, 87, 5}

Out= {20, 49, 87, 5}

Cool, now let's check their values.

In:= PropertyValue[x, EdgeWeight]

Out= {1, 10, 30, 60}

Wait, what... That's strange, because in this answer, that syntax is working...

Okay, let's try SetProperty, that's what it's for.

SetProperty[x, EdgeWeight -> {20, 49, 87, 5}]
<<Returns graph of x, but with initial weights as the edge labels, but ok>>

Now let's check...

In:= PropertyValue[x, EdgeWeight]

Out= {1, 10, 30, 60}

Um...

Let's try checking just the first value?

In:= PropertyValue[{x, 1}, EdgeWeight]

Version 10.1.0 for Linux x86 (64-bit)

I can reproduce the issues on Version 10.1.0 (on Wolfram Programming Cloud). That is,

{ PropertyValue[x, EdgeWeight] = {20, 49, 87, 5}; x,  PropertyValue[x, EdgeWeight] }
(* {{20, 49, 87, 5}, {1, 10, 30, 60}} *)

and

{y = SetProperty[x, EdgeWeight -> {20, 49, 87, 5}],PropertyValue[y, EdgeWeight] }

both give Work-arounds:

x = Graph[{1, 2, 3, 4}, {1 <-> 2, 3 <-> 2, 3 <-> 4, 1 <-> 4},
EdgeWeight -> {1, 10, 30, 60}, VertexLabels -> "Name",
EdgeLabels -> "EdgeWeight"];

{(PropertyValue[{x,#}, EdgeWeight] =#2)&@@@ Transpose[{EdgeList[x],{20, 49, 87, 5}}];
x, PropertyValue[x,EdgeWeight]}

and

x = Graph[{1, 2, 3, 4}, {1 <-> 2, 3 <-> 2, 3 <-> 4, 1 <-> 4},
EdgeWeight -> {1, 10, 30, 60}, VertexLabels -> "Name",
EdgeLabels -> "EdgeWeight"];

{Fold[SetProperty[{#,#2[]},EdgeWeight ->#2[]]&,x,
Transpose[{EdgeList[x], {20, 49, 87, 5}}]],
PropertyValue[x, EdgeWeight]}

both give • That looks like a bug; do you agree? May 7 '15 at 5:25
• @Mr.Wizard, yes it does.
– kglr
May 7 '15 at 6:03
• I've gotta say that after all my false "peter and the wolf" accusations (where it turns out I'm just stupid and it's not a bug), it's a little satisfying to finally find a bug. I was pulling out my hair last night for hours trying to figure out what I did wrong. Oh and I added my version number (10) to the OP. May 7 '15 at 14:02
• @kguler, also, I think there may be a typo in your 2nd workaround, if you run that code it throws an error because y2 is undefined. May 7 '15 at 14:13
• One more quick question if that's okay: Your 1st workaround worked great for me, so I tried making a function out of it: ChangeEdgeWeights[gin_, newEWs_] := (pair = {(PropertyValue[{gin, #}, EdgeWeight] = #2) & @@@ Transpose[{EdgeList[gin], newEWs}]; gin, PropertyValue[gin, EdgeWeight]}; ]; Return[First@pair];) But it's giving me an error saying that my input graph "is not a symbol" in the property value assignment. Actually, maybe it's a warning because it still returns the right values. What's the deal with that? Thanks! May 7 '15 at 14:30